6

I've stumbled upon a strange issue. Lets say I have folder in main domain directory: /myfolder

When I try to access index of files in this folder I go to: myurl.com/myfolder And it works without any problems. Now when I put .htaccess with password protection in this folder like:

AuthUserFile /home/mywebsite/.htpasssomerandomname
AuthType Basic
AuthName "Authentication Required"
Require valid-user

Suddenly instead of asking me for password when I try to access myurl.com/myfolder I get 404 wordpress template page. Below is my .htaccess in main WordPress folder.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Any ideas what might be a problem?

Greg Viv
  • 817
  • 1
  • 8
  • 22

1 Answers1

22

I don't understand why but it seems adding below line to .htaccess inside protected folder fixed this issue:

ErrorDocument 401 "Authorisation Required"

I've found this fix online but without explanation why it actually works that way. Anyone can add explanation? It just feels like it really shouldn't be like that.

Greg Viv
  • 817
  • 1
  • 8
  • 22
  • 1
    If the server throws a `401` error, your htaccess will load the message `Authorisation Required`. This message can also be replaced by a link to a (custom) page with more information about the error. – Timothy Jun 28 '16 at 12:12
  • 1
    OOOOH, F\/CK 1t 4LL, THANKS MAN!, I've been suffering with it for hours.. – Attila Fulop Aug 15 '16 at 12:25
  • After 3 days and over 5 hours of work, this was finally it. All this time I suspected rewrite rules and faulty logic. I even got as far as creating the "error files" for 404, 403, 500... Finally, it was actually the 401. The 401 is not stated in the cpanel gui, so I never suspected it. The cpanel logs did not help, and the 404 error masked the 401. Thank you so much. I can finally sleep in peace. – Morgus Lethe Jan 22 '20 at 18:34