【问题标题】:Issue with redirection of a folder with mod_alias使用 mod_alias 重定向文件夹的问题
【发布时间】:2010-12-29 23:34:51
【问题描述】:

this thread 之后的另一个问题。我无法解决的唯一剩余项目是现在不存在的文件夹“/team/”的列表,但是如果我将其添加到我的 .htaccess 文件中,它会破坏所有其他 .htaccess 中文件的条目那个文件夹,即

redirect 301 /team/ /team.html
redirect 301 /team/joe_bloggs.htm /team.html
redirect 301 /team/joe_bloggs.html /team.html
redirect 301 /team/bill_smith.htm /team.html
redirect 301 /team/bill_smith.html /team.html

如果我随后尝试访问 /team/joe_bloggs.htm,它会带我去

/team.html/joe_bloggs.htm

如果我能解决这个问题,它可能会帮助我了解如何解决我的原始问题并减少我的 .htaccess 文件中大量的重定向页面列表,因此我们非常感谢您的帮助。

【问题讨论】:

    标签: .htaccess directory http-status-code-301 mod-alias


    【解决方案1】:

    您需要更改顺序,并在末尾输入“redirect 301 /team/ /team.html”。 它逐行读取,如果找到合适的内容,则会替换它。

    此外,我认为您需要学习添加 ^ 和 $ 字符。 ^ 表示表达式应该开始,$ 表示表达式应该结束。 所以,^/team/$ 的意思是,它应该是 /team/ 并且它不会匹配 /team/joe_bloggs.htm

    【讨论】:

    • 感谢您的建议和提示。我会立即实施它们。
      干杯,祝你新年快乐
      Martin
    【解决方案2】:

    Redirect directive 适用于路径前缀。在这种情况下,您的第一个指令 (/team/) 中使用的路径前缀匹配,并且路径的其余部分将附加到新的 URL 路径。

    […] 任何以 URL-Path 开头的请求都会在目标 URL 的位置向客户端返回重定向请求。匹配的 URL-Path 之外的附加路径信息将附加到目标 URL

    改用RedirectMatch

    RedirectMatch 301 ^/team/ /team.html
    

    【讨论】:

    • 感谢您的建议。
      干杯,祝您新年快乐
      Martin
    猜你喜欢
    • 2011-08-14
    • 2014-09-05
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    相关资源
    最近更新 更多