如何将错误403重定向到.htaccess中的根目录

编程入门 行业动态 更新时间:2024-10-19 15:40:10
本文介绍了如何将错误403重定向到.htaccess中的根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Apache方面不是很坚定,所以如果这个问题看起来有点明显,请原谅. 我想通过.htaccess文件将在特定目录中导致错误403的请求重定向到我的Web服务器根目录. 因此 thedomain/secretlair/-> 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 thedomain/secretlair/ -> thedomain

到目前为止,我使用过:

so far i used:

RewriteEngine on RewriteBase / RewriteRule (.*) thedomain/$1 [R=301,L]

可以工作,但也会产生重定向的问题 thedomain/secretlair/thefile.txt 到 thedomain/thefile.txt

which works but creates the problem of also redirecting thedomain/secretlair/thefile.txt to 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 thedomain/

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

Make sure to clear your browser cache before testing this change.

更多推荐

如何将错误403重定向到.htaccess中的根目录

本文发布于:2023-11-01 02:08:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547940.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:根目录   如何将   重定向   错误   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!