【问题标题】:Apache - redirecting to same URL but with query string appendedApache - 重定向到相同的 URL,但附加了查询字符串
【发布时间】:2015-11-15 06:38:39
【问题描述】:

我正在尝试在 Apache 上执行重写规则,它会重写 url 以将查询字符串附加到末尾:

http://example.org/page1.aspx

http://example.org/page1.aspx?query=12345

问题是我何时应用此规则:

RewriteRule ^\/page1.aspx$ http://example.org.aspx?query12345 [NC,L,R=301]

我最终得到一个重定向循环。

任何帮助将不胜感激!

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    您需要先使用条件来检查查询字符串是否为空:

    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^/?page1\.aspx$ %{REQUEST_URI}?query=12345 [NC,L,R=301]
    

    确保在测试之前清除浏览器缓存。

    【讨论】:

    • 太棒了!非常感谢您的快速回复,它有效。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-10
    • 1970-01-01
    • 2014-05-07
    • 2012-05-17
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    相关资源
    最近更新 更多