如何将错误403重定向到.htaccess中的根目录
我在Apache方面不是很坚定,所以如果这个问题看起来有点明显,请原谅. 我想通过.htaccess文件将在特定目录中导致错误403的请求重定向到我的Web服务器根目录. 因此 https://thedomain.com/secretlair/->
I am not very firm in Apache, so please excuse if the question might seem a bit obvious. I would like to redirect requests that would result in an Error 403 in specific directories to my webservers root by means of a .htaccess file. so https://thedomain.com/secretlair/ -> https://thedomain.com
到目前为止,我使用过:
so far i used:
RewriteEngine on
RewriteBase /
RewriteRule (.*) https://thedomain.com/$1 [R=301,L]
可以工作,但也会产生重定向的问题 https://thedomain.com/secretlair/thefile.txt 到
which works but creates the problem of also redirecting https://thedomain.com/secretlair/thefile.txt to https://thedomain.com/thefile.txt
要进行这项工作,我需要更改什么?
what do I need to change to make this work?
非常感谢!
您可以仅使用ErrorDocument
处理程序来处理403
错误,而不是像这样的重写规则:
You can just use a ErrorDocument
handler for 403
error instead of a rewrite rule like this:
ErrorDocument 403 https://thedomain.com/
在测试此更改之前,请确保清除浏览器缓存.
Make sure to clear your browser cache before testing this change.