【问题标题】:mod_rewrite old Domain Rules to new Domainmod_rewrite 旧域规则到新域
【发布时间】:2013-02-11 17:20:50
【问题描述】:

我正在尝试将一些旧动态链接转发到新目标

旧的 Link 使用了 RewriteRule

http://www.olddomain.com/index.php?cms=blog&action=..

所以我会将cms=blog 转发到一个新域http://www.newdomain.com/blog

【问题讨论】:

  • 您知道-1 先生是什么大问题。并非所有事情都容易向 Google 解释。你能解释的人不会听你的!感谢您的 -1
  • 这:RewriteRule ^/docs/(.+) http://new.example.com/docs/$1 [R,L] 不起作用。它应该类似于:RewriteRule ^docs/(.+) http://new.example.com/docs/$1 [R,L]。但是不清楚你想要什么,如果你想让别人完全理解你需要什么,请花一些时间在你的问题中包含一些完整的 URL 示例。规则是不够的,特别是当它们是问题的原因时。
  • 嘿,faa,再次感谢您的回复。我正在编辑我的问题以更好地解释。我正在尝试这种方式,但没有解决。 RedirectMatch ^/?cms=blog(.*) http://www.newdomain.com/blog/ [R=301,L]

标签: .htaccess url mod-rewrite redirect rewrite


【解决方案1】:

要匹配查询字符串,您可以使用RewriteCond 指令。您需要在 www.olddomain.com/.htaccess 中放置的完整规则是:

RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)cms=blog(&|$)
RewriteRule ^index\.php$ http://www.newdomain.com/blog? [R=302,L]

如有必要,将 302 更改为 301。

【讨论】:

  • 嗨,萨尔曼,谢谢。转发正在工作,但 URL 现在看起来像这样 http://www.newdomain.com/blog/?p=shop&action=... 它应该只转发到 http://www.newdomain.com/blog 而不需要之前的条件。
  • 我已经编辑了我的答案。请注意网址末尾的?,它是必需的。
  • 你是当时的王者 ;)
猜你喜欢
  • 2012-05-09
  • 2010-09-17
  • 2019-08-19
  • 1970-01-01
  • 2021-07-10
  • 2011-04-23
  • 1970-01-01
  • 2015-08-16
  • 1970-01-01
相关资源
最近更新 更多