apache - 如何将错误 403 重定向到 .htaccess 中的 root

标签 apache .htaccess redirect mod-rewrite apache2

我对 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.txthttps://thedomain.com/thefile.txt

我需要更改什么才能使其正常工作?

非常感谢!

最佳答案

您可以仅使用 ErrorDocument 处理程序来处理 403 错误,而不是像这样的重写规则:

ErrorDocument 403 https://thedomain.com/

在测试此更改之前,请确保清除浏览器缓存。

关于apache - 如何将错误 403 重定向到 .htaccess 中的 root,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47071609/

相关文章:

php - 将 id 传递给表中显示的计数的 url

redirect - Nginx 重写问号

forms - 成功登录Tomcat表单后重定向

.htaccess - htaccess RewriteRule *.php 到/*/

java - Tomcat服务器默认页面查询

java | Apache 汤姆猫 |抓取异常并重启服务器

php - 测量 PHP 性能

.htaccess - 如何在 codeigniter 中将 HTTP 调用重定向到 HTTPS 以获取 Web 服务?

.htaccess - htaccess 在 RewriteRule 之前重定向?

linux - httpd/apachectl 服务无法在 RHEL 7 上启动