0

I have a Laravel application where I want to restrict the access to a specific URL (specifically the url of the api documentation) /api/documentation. I've seen this post and I tried it but I keep getting Internal Server Error, I don't know how to put the code.

This is my .htaccess right here. So far the default laravel .htaccesss:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Where or how do I have to put the code on this post?

Thank you.

Alberto
  • 1,348
  • 2
  • 14
  • 28

1 Answers1

0

I'd probably use a different form of authentication. But if you're set on using HTTP auth, at least make sure you use bcrypt or something secure when generating your htpasswd file.

But to answer your question...

Your .htaccess file should have something like:

AuthType Basic
AuthName "Super Secret"
AuthUserFile /some/location/where/your/.htpasswd/file/is
Require valid-user
Ewan
  • 181
  • 8
  • But that will lock every single url in my site, right? I just want to restrict a specific URL that is **/api/documentation** – Alberto Feb 10 '20 at 13:28
  • https://medium.com/oceanize-geeks/laravel-middleware-basic-auth-implementation-88b777361b5c – Ewan Feb 10 '20 at 13:30