【问题标题】:Failed to use Apache RewriteRule无法使用 Apache RewriteRule
【发布时间】:2012-01-18 07:28:25
【问题描述】:

我想使用 Apache RewriteRule 将 URL 目标页面更改为 abc.php。我已将 RewriteEngine 设置为 On,但我发现了这个问题。

我使用的正则表达式:

RewriteRule ^viewthread\.php.tid=12345$ abc.php

要匹配的 URL 字符串:

viewthread.php?tid=12345

为什么没有匹配成功?

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    使用查询字符串重写 URL 比重写普通 URL 稍微复杂一些。你必须写这样的东西:

    RewriteCond %{REQUEST_URI}  ^/viewthread\.php$
    RewriteCond %{QUERY_STRING} ^tid=12345$
    RewriteRule ^(.*)$ http://mydomain.site/abc.php [R=302,L]
    

    查看这些文章以获得更多帮助:

    【讨论】:

      【解决方案2】:

      我想是因为你错过了 ?在规则中...

      RewriteRule ^viewthread.php?tid=12345$ abc.php
      

      【讨论】:

        【解决方案3】:

        不应该是:

        RewriteRule ^/viewthread\.php\?tid=12345$ /abc.php
        

        【讨论】:

        • 打开日志并粘贴一个 sn-p,这样我们就可以确切地知道发生了什么
        猜你喜欢
        • 1970-01-01
        • 2017-04-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-17
        • 2016-02-07
        相关资源
        最近更新 更多