.htaccess password protected folder goes to 404 page

假装没事ソ 提交于 2019-12-07 05:09:41

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/38075238/htaccess-password-protected-folder-goes-to-404-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!