.htaccess密码保护的文件夹进入404页 [英] .htaccess password protected folder goes to 404 page

查看:70
本文介绍了.htaccess密码保护的文件夹进入404页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了一个奇怪的问题。
可以说我在主域目录中有一个文件夹:/ myfolder

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

当我尝试访问该文件夹中文件的索引时,我转到:myurl.com/ myfolder
而且它没有任何问题。
现在,当我将具有密码保护的.htaccess放在此文件夹中时,例如:

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

突然,当我尝试访问myurl.com/myfolder时,我没有询问密码,而是得到404 wordpress模板页面。
以下是我在WordPress主文件夹中的.htaccess。

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?

推荐答案

我不明白为什么,但是似乎在受保护的文件夹中的.htaccess中添加了以下行,从而解决了此问题:

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.

这篇关于.htaccess密码保护的文件夹进入404页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆