authentication - .htaccess mod-rewrite 与子文件夹身份验证冲突

标签 authentication .htaccess mod-rewrite

我有一个站点,它使用 .htaccess 将所有对不存在的文件/文件夹的请求重定向到索引文件:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L]
RewriteRule !admin/* index.php [NC,L]

有一个文件夹“admin/”,它在 .htaccess 中有以下内容用于身份验证:
AuthType Basic
AuthName "admin"
AuthUserFile "/path/to/passwd"
require valid-user

在“admin/”中添加 auth .htaccess 文件会导致请求被 mod-rewrite 捕获,而不是提供身份验证响应。我尝试了一些不同的方法来解决这个问题(包括这个: htaccess rewrite and auth conflict ),但无法购买。

谢谢。

编辑:如果我已经通过身份验证,重写规则将允许我访问“admin/”文件夹。因此,似乎是身份验证挑战正在做一些奇怪的事情。

最佳答案

我有同样的问题,我也发现了这个相关的问题:htaccess rewrite and auth conflict

那里的答案之一使我了解了我的问题。 Apache 试图查找 401 错误的文档但失败了。我添加了一个文档/401.html 并将其添加到带有 Auth 语句的 .htaccess 文件中。

错误文档 401/401.html

现在,它对我有用!

关于authentication - .htaccess mod-rewrite 与子文件夹身份验证冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3144401/

相关文章:

用于 Web 用户身份验证的 Java 选项

authentication - 使用 Spring Web 服务添加 Spring Security @Secured 注释会禁用 Web 服务端点

php - 将 Wordpress Post 与 Cakephp3 集成

Apache(不是浏览器)正在缓存我的文件

apache - htaccess 在重写规则中添加 @ 或空格时导致 500 内部错误

.htaccess - RewriteRule接受2个参数

.htaccess - 如何使用 htaccess 文件重定向多个 url?

apache - htaccess 404 停止工作

c# - 如何验证客户端应用程序以信任从其发送的消息

objective-c - mount_smbfs 上出现身份验证错误