【问题标题】:htaccess redirect dynamic URL to another dynamic URLhtaccess 将动态 URL 重定向到另一个动态 URL
【发布时间】:2014-10-03 06:47:25
【问题描述】:

我需要将一个动态 URL 重定向到另一个,但参数略有改变。这是原始网址:

http://www.EXAMPLE.com/index.php?main_page=index&cPath=5

需要重定向到

http://www.EXAMPLE.com/index.php?main_page=index&cPath=25

我尝试了很多不同的变体,但似乎没有一个有效。

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5$
RewriteRule ^/(index\.php|)$ http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 [L,R=301]

我快疯了...谁能指出我正确的方向并告诉我我做错了什么?

【问题讨论】:

    标签: php regex .htaccess mod-rewrite redirect


    【解决方案1】:

    我相信前导斜线是您模式中的问题。在您的根 .htaccess 中尝试此规则:

    RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5$ [NC]
    RewriteRule ^/?(index\.php)?$ /$1?main_page=index&cPath=25 [NC,L,R=301]
    

    【讨论】:

    • aaaah,如此漂亮的解决方案,非常感谢!
    【解决方案2】:

    也许没有条件?

    RewriteEngine on
    rewriterule ^index.php?main_page=index&cPath=5$ http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 [r=301,nc]
    

    【讨论】:

    • QUERY_STRING 在 RewriteRule 中不可用,因为 RewriteRule 处理的是路径,所以应该使用 RewriteCond。
    猜你喜欢
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    相关资源
    最近更新 更多