My issue:
My website consists of some files in the root folder, as well as a password-protected sub-folder, set in my htaccess. When I try to access the sub-folder it prompts me for the password, as it should. However, it prompts me for the password twice, and after entering the correct password twice, it then throws a 404 error. If I enter an incorrect password, it keeps asking for the password.
After inputting the password, I am in fact logged in, because if I try to access a specific part of that subfolder (i.e. myurl.com/subfolder/index.php), I can access it. But obviously the site shouldn't throw a 404 error first.
What I've tried:
I have seen that other people have a similar issue, regarding password-protected sub-folders and 404 errors. However, my issue is slightly different, as I actually get to input a password. Therefore the common solution of adding ErrorDocument 401 "Authorisation Required"
has not solved the issue.
Code:
This is the htaccess for the root folder:
#Redirects to the https version of site
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
## Removes php extensions
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#Allow password for subfolder
ErrorDocument 401 "Authorisation Required"
And this is the htacess for the subfolder:
#Password for subfolder
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile myurl/mysubfolder/.htpasswd
Require valid-user
Any help is much appreciated!