【问题标题】:Help with mod rewrite redirecting to new url帮助 mod rewrite 重定向到新的 url
【发布时间】:2009-09-02 02:16:36
【问题描述】:

以下 url 重写工作正常,但不会重定向到新 url。

RewriteRule ^test-(.*)-(.*)\.html$ /test.php?&abc=$1&xyz=$2/ [L]

【问题讨论】:

    标签: php apache mod-rewrite


    【解决方案1】:

    如果您想强制将浏览器重定向到该 URL,您需要使用 R 标志:

    RewriteRule ^test-(.*)-(.*)\.html$ /test.php?&abc=$1&xyz=$2/ [R,L]
    

    【讨论】:

    • 我刚刚尝试添加 [R,L] 但没有任何反应。它不会重定向到新的 url。
    • 它是否正确执行了 test.php 但只是不重定向?
    • 我会删除最后的斜线: RewriteRule ^test-(.*)-(.*)\.html$ /test.php?&abc=$1&xyz=$2 [R,L]
    • 我刚刚又测试了一遍。如果我尝试访问新的 url (example:) test-one-two.html,它会重定向到动态 url。但是当我尝试访问动态 url 时,它不会重定向到新的 url。
    • @Amy:mod_rewrite 的主要目标是不重定向,重定向只发生在用户看不到正在发生的事情的 Web 服务器内部。如果您希望用户看到重定向发生,请使用 R 标志,例如 [R=301,L]。我不知道是指定它需要的 HTTP 代码还是可选的。
    猜你喜欢
    • 2014-09-26
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 2012-04-18
    • 2023-04-05
    相关资源
    最近更新 更多