I have a password protected directory at example.com/staging
.
If I enter example.com/js
I get a folder listing.
But if I enter example.com/staging
, I get a 404 error page generated by the Laravel site at example.com
(not example.com/staging
), rather than a password box. Why is this?
Here is my .htaccess file in the public_html folder (the home directory) at example.com
:
AddType application/x-httpd-php70 .php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
And my .htaccess file at example.com/staging
:
AuthType Basic
AuthName "Staging"
AuthUserFile "/home/example/.htpasswds/public_html/staging/passwd"
require valid-user
2
Answers
I found the answer here
Add the below line to the htaccess file within the protected directory:
Remove the quotation marks from the directory path for
AuthUserFile
, those shouldn’t be there.Your directory path looks odd too, your
.htpasswd
file shouldn’t be located in the middle of the path, but should be at the end. For example:I’m sure it is, but as an added point, you are encrypting your password correctly? Apache will not accept a password that has not been correctly encrypted. You can use this website to help with that if required: http://www.htaccesstools.com/htpasswd-generator/