我对 Apache 不是很坚定,所以如果这个问题看起来有点明显,请原谅。 我想通过 .htaccess 文件将特定目录中导致错误 403 的请求重定向到我的网络服务器根目录。 所以https://thedomain.com/secretlair/ -> https://thedomain.com
到目前为止我用过:
RewriteEngine on
RewriteBase /
RewriteRule (.*) https://thedomain.com/$1 [R=301,L]
它可以工作,但也会产生重定向问题 https://thedomain.com/secretlair/thefile.txt至 https://thedomain.com/thefile.txt
我需要更改什么才能使其正常工作?
非常感谢!
最佳答案
您可以仅使用 ErrorDocument
处理程序来处理 403
错误,而不是像这样的重写规则:
ErrorDocument 403 https://thedomain.com/
在测试此更改之前,请确保清除浏览器缓存。
关于apache - 如何将错误 403 重定向到 .htaccess 中的 root,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47071609/