问题描述
限时送ChatGPT账号..我对 Apache 不是很了解,所以如果问题看起来有点明显,请原谅.我想通过 .htaccess 文件将在特定目录中导致错误 403 的请求重定向到我的网络服务器根目录.所以 https://thedomain/secretlair/ -> https://thedomain
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/secretlair/ -> https://thedomain
到目前为止我使用过:
RewriteEngine on
RewriteBase /
RewriteRule (.*) https://thedomain/$1 [R=301,L]
这有效但也产生了重定向的问题https://thedomain/secretlair/thefile.txt 到 https://thedomain/thefile.txt
which works but creates the problem of also redirecting https://thedomain/secretlair/thefile.txt to https://thedomain/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/
确保在测试此更改之前清除浏览器缓存.
Make sure to clear your browser cache before testing this change.
这篇关于如何在 .htaccess 中将错误 403 重定向到 root的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论