【问题标题】:Redirect a url along with .htaccess and re-write rules gone wrong将 url 与 .htaccess 一起重定向并重写规则出错
【发布时间】:2020-08-31 12:21:53
【问题描述】:

我正在尝试通过 .htaccess 将 http://localhost/anay-bose 重定向到 http://localhost/anay-bose/1338.html(实际有效的 url)

这是我的规则:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9])$ /anaybose/$1 [R=301]
Redirect /anay-bose http://localhost/anay-bose/1338.html

问题是它正在重定向到诸如 http://localhost/anay-bose/1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/ 之类的 URL 1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/1338.html/1338。 html

很多 1338.html 而我只需要一个 1338.html

寻找洞察力。

【问题讨论】:

  • 你陷入了无限循环。 anay-bose 将以 /anay-bose 开头的所有内容重定向到 anay-bose/1338.html。但是 anay-bose/1338.html 再次匹配该规则并且 anay-bose 再次被重定向。尝试#### RewriteEngine on Redirect 301 anay-bose localhost/anay-bose/1338.html
  • “寻找见解” - 然后从阅读文档开始吧?对于Redirect,它清楚地解释了该指令如何在 URL 路径上进行 prefix 匹配,并将任何多余的附加到目标 URL。

标签: javascript php .htaccess


【解决方案1】:

您需要通过RedirectMatch Directive对其进行一些改进

RedirectMatch ^/anay-bose$ http://localhost/anay-bose/1338.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多