【发布时间】:2015-09-25 04:23:04
【问题描述】:
在我的公用文件夹中,我有一个想要使用 .htpasswd 保护的日志文件夹。我的应用程序文件夹实际上是在公共内部(该网站是在考虑到这一点的情况下构建的,因此不值得移动应用程序)。当我尝试访问受密码保护的文件夹时,它只是将我重定向到 404。如果我取出 MVC 重写部分,它就可以工作。这是我的目录结构,以防万一。
root/
public/
app/
start.php
.htaccess
...
logs/
.htaccess
.htpasswd
errorlog.md
index.php
.htaccess
vendor/
这是我认为重要的 /public 中的 .htaccess 部分。
<IfModule mod_rewrite.c>
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} !cfnw-user [NC]
RewriteRule ^resources/newspaper http://example.com/error/401 [NC,L]
# Force to exclude the trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.+)/$ $1 [R=307,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [QSA,L]
</IfModule>
这是 /logs 中的 .htaccess。
AuthType Basic
AuthName "Log files. Sensitive information."
AuthUserFile /home/site/public/logs/.htpasswd
Require valid-user
我想知道如何在不重定向到 404 的情况下使密码保护工作。
【问题讨论】:
标签: apache .htaccess redirect passwords http-status-code-404