2014-01-23 76 views
0

花了一天時間閱讀遍佈整個網絡的數百個變體,但仍無法找到一個適用於此的明確答案。還有一個htaccess重定向請求 - 舊域名到新域名和舊頁面到新頁面

移動舊域名新域名新網站結構老的網站結構,所以我找最好的,搜索引擎友好,重定向代碼:

  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/ 
+0

什麼是不工作呢? –

回答

0

你應該堅持只使用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] 
+0

這樣做 - 謝謝! – user9373

+0

也許不是 - 我將這添加到舊網站的htaccess而不是新網站,並且好像舊的搜索鏈接正確映射到新頁面。但是,當新網站出現在列表中時,鏈接在新網站上顯示404!已經添加了頁面重定向到newsite htaccess,現在看起來確定。但是,這裏最好的做法是什麼?我應該域名重定向到oldsite htaccess和頁面重定向到newsite htacces或只是從DNS重定向舊域名,並讓頁面在newsite htaccess中重定向?困惑! – user9373

+0

@ user9373沒關係,只要舊的URL 301重定向到新的URL,無所謂的域名解析 –

相關問題