【问题标题】:.htaccess redirect QUERY_STRING and not propage QUERY_STRING.htaccess 重定向 QUERY_STRING 而不是宣传 QUERY_STRING
【发布时间】:2013-06-12 13:08:41
【问题描述】:

我想永久重定向

/ask?search%255Bto%255D=test 

/question/test

我添加了我的 .htaccess

RewriteCond %{QUERY_STRING} ^search%255Bto%255D=([a-zA-Z0-9\-]*)
RewriteRule ^ask$ /question/%1 [R=permanent,L]

有了这些额外的行,我得到了

/ask?search%255Bto%255D=test 

重定向到

/question/test?search%255Bto%255D=test

我的问题是我的重定向网址中仍然有查询字符串 (?search%255Bto%255D=test)。

我想要:

/question/test

而不是

/question/test?search%255Bto%255D=test

感谢您的帮助

【问题讨论】:

    标签: apache .htaccess mod-rewrite query-string


    【解决方案1】:

    如果您想清除查询字符串,只需用问号结束您的目标 URL。尝试将重写规则更改为:

    RewriteRule ^ask$ /question/%1? [R=permanent,L]
    

    这指定了一个新的空查询字符串,因此旧的查询字符串不会作为重定向 URL 的一部分发送。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-09
      • 2011-11-06
      • 2017-12-04
      • 2017-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多