代码之家  ›  专栏  ›  技术社区  ›  zantafio

如何将错误403重定向到根目录。htaccess

  •  3
  • zantafio  · 技术社区  · 7 年前

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

    我需要做什么改变才能让它工作?

    谢谢!

    1 回复  |  直到 5 年前
        1
  •  4
  •   anubhava    7 年前

    你可以用一个 ErrorDocument 处理程序 403 错误,而不是这样的重写规则:

    ErrorDocument 403 https://thedomain.com/