【问题标题】:Properly 301 redirect an URL with parameters to a different site正确 301 将带有参数的 URL 重定向到不同的站点
【发布时间】:2014-06-07 17:39:18
【问题描述】:

现在我有一个过时的 URL,它正在被 404 处理:

http://mysite.com/category/?tag=blue-example

需要重定向到:

http://subdomain.mysite.com/blue/

这不起作用:

Redirect 301 /category/?tag=blue-example http://subdomain.mysite.com/blue/

如何正确重写此 URL?

【问题讨论】:

  • 什么不起作用?你到底把那条线放在哪里了?重定向的 URL 是否应该依赖于 QUERY_STRING?你的问题很模糊。
  • 抱歉含糊其辞。当我使用该重定向规则时,原始 URL 不会重定向到新 URL。这有意义吗?

标签: apache mod-rewrite redirect http-status-code-301


【解决方案1】:

mod_alias 只检查 URI 路径而不是查询(? 之后的部分)。但是您可以为此使用mod_rewrite

RewriteEngine on
RewriteCond %{QUERY_STRING} =tag=blue-example
RewriteRule ^category/$ http://subdomain.example.com/blue/? [L,R=301]

【讨论】:

  • 谢谢秋葵!这似乎是我正在寻找的,但由于某种原因,它不适用于我的本地安装。我正在使用一堆其他有效的 mod_rewrite 规则。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-05
  • 2018-12-21
  • 2014-01-06
  • 2019-12-18
  • 2012-08-12
  • 2021-12-28
  • 2011-07-03
相关资源
最近更新 更多