【问题标题】:yet another htaccess redirect request - old domain to new domain and old pages to new pages另一个 htaccess 重定向请求 - 旧域到新域和旧页面到新页面
【发布时间】:2014-02-14 06:22:54
【问题描述】:

花了一天时间阅读了整个网络上的数百种变体,但仍然找不到适用于此的明确答案。

将旧域上的旧站点结构移动到新域上的新站点结构,因此我正在寻找最好的、搜索引擎友好的重定向代码:

  1. 将所有 old-domain.com 和 www.old-domain.com 流量永久重定向到 www.new-domain.com。

  2. 添加从 old-domain.com/old-page.html 和 www.old-domain.com/old-page.html 到 www.new-domain.com/new-page/ 的特定重定向

这是我所拥有的 - 但它不起作用 - 请有人为我改进/修复这个问题。非常感谢!

RewriteEngine on 
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]
redirect 301 /old-index.html http://www.new-domain.com/
redirect 301 /old-page-1.html http://www.new-domain.com/new-1/
redirect 301 /old-page-2.html http://www.new-domain.com/new-2/
redirect 301 /old-page-3.html http://www.new-domain.com/new-3/

【问题讨论】:

  • 这有什么问题?

标签: .htaccess redirect dns


【解决方案1】:

您应该坚持只使用 mod_rewrite 或 mod_alias 而不要将两者混合使用。订单很重要

mod_alias:

Redirect 301 /old-index.html http://www.new-domain.com/
Redirect 301 /old-page-1.html http://www.new-domain.com/new-1/
Redirect 301 /old-page-2.html http://www.new-domain.com/new-2/
Redirect 301 /old-page-3.html http://www.new-domain.com/new-3/
Redirect 301 / http://www.new-domain.com/

mod_rewrite:

RewriteEngine on 
RewriteRule ^old-index.html$ http://www.new-domain.com/ [R=301,L]
RewriteRule ^old-page-1.html$ http://www.new-domain.com/new-1/ [R=301,L]
RewriteRule ^old-page-2.html$ http://www.new-domain.com/new-2/ [R=301,L]
RewriteRule ^old-page-3.html$ http://www.new-domain.com/new-3/ [R=301,L]
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]

【讨论】:

  • 也许不是——我在旧站点而不是新站点上将其添加到 htaccess 中,并且似乎可以将旧搜索链接正确映射到新页面。但是,当newsite 出现在列表中时,newsite 上的链接是404ing!只添加了页面重定向到newsite htaccess,现在看起来还可以。但是这里的最佳实践是什么?我应该将域重定向到旧站点 htaccess 并将页面重定向到新站点 htacces 还是只是从 DNS 重定向旧域并将页面重定向到新站点 htaccess 中?困惑!
  • @user9373 没关系,只要旧网址301重定向到新网址,域名解析到什么服务器都无所谓
  • 这就是我的想法 - 但是 Bing 已将 newdomain.com/ 编入索引为 newdomain.com/oldindexpage.html,并且由于重定向在 oldomain htaccess 中,它在 newdomain 上是 404!
  • 它似乎直接进行了域重定向,忽略了上面的页面重定向,当它到达新域时它找不到 /oldindexpage.html
  • @user9373 你确定这不是缓存问题吗?
猜你喜欢
  • 2011-09-24
  • 1970-01-01
  • 1970-01-01
  • 2019-07-22
  • 2018-10-09
  • 1970-01-01
  • 2021-11-28
  • 2013-02-10
  • 2011-11-04
相关资源
最近更新 更多