【问题标题】:URL redirect with query strings - htaccess带有查询字符串的 URL 重定向 - htaccess
【发布时间】:2014-07-08 05:04:24
【问题描述】:

这真的让我很烦,我已经学习了一些教程,但就是无处可去。我正在尝试从以下位置进行 301 重定向:

/webpage-mackay.php?wp=Mission

到:

http://domain.org.au/webpage.php?wp=Mackay%20Mission

我尝试过这样写:

RewriteCond %{QUERY_STRING} ^wp=Mission$
RewriteRule ^/webpage-mackay\.php$ http://domain.org.au/webpage.php?wp=Mackay%20Mission [R=301,L]

和:

RewriteCond   %{REQUEST_URI}    ^/webpage-mackay.php$
RewriteCond   %{QUERY_STRING}   ^wp=Mission$
RewriteRule   ^(.*)$ http://domain.org.au/webpage.php?wp=Mackay%20Mission   [R=301,L]

但结果是:

http://domain.org.au/webpage.php?wp=Mission

我错过了什么吗?我使用了thisthis 作为参考

【问题讨论】:

  • 浏览器可能会缓存 301 响应。所以可能会缓存错误的响应。
  • 我在另一个浏览器和另一个服务器上尝试过,仍然得到相同的结果。
  • 我看到的唯一原因是另一个重定向指令,例如配置或 htaccess 中的Redirect

标签: .htaccess url redirect query-string http-status-code-301


【解决方案1】:

我发现您的第一次尝试有 2 个问题:在 RewriteRule 中不需要前导斜杠,并且 %20 不起作用,因为“%”是一个特殊字符。 您可以在这里尝试:

# Solution 1 : with a space character in the final URL
RewriteCond %{QUERY_STRING} ^wp=Mission$
RewriteRule ^webpage-mackay\.php$ http://domain.org.au/webpage.php?wp=Mackay\ Mission [R=301,L]

# Solution 2 : with the %20 in the final URL
RewriteCond %{QUERY_STRING} ^wp=Mission$
RewriteRule ^webpage-mackay\.php$ http://domain.org.au/webpage.php?wp=Mackay\%20Mission [R=301,L,NE]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 2016-01-18
    • 2020-12-14
    • 1970-01-01
    • 2015-05-27
    • 2021-04-05
    • 1970-01-01
    相关资源
    最近更新 更多