2014-04-23 173 views
1

我正在發佈我的一個網站的更新版本很快在一個新的域名,我想知道如何使它可以使舊網址指向我的新網站,因爲它有相當的很多有價值的反向鏈接。重定向舊域名反向鏈接到新域名

我已閱讀有關如何使301重定向在.htaccess中,但我需要更高級的東西,因爲我的一些網址結構已經改變。看下面的例子。

olddomain.com 
newdomain.com 
- These will do just fine with the 301 redirect 

olddomain.com/author/username 
newdomain.com/user/username 
- Different URL structure but I want the old urls to redirect towards the new url 

olddomain.com/add 
newdomain.com/submit 
- Different page name for the same functionaly, would like to have these redirect correctly as well 

我不知道如何去創造這些最後兩個重定向所以如果有人可以點我到這將是偉大正確的方向! :)

回答

2

將這個代碼在你DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On 

RewriteCond %{HTTP_HOST} olddomain\.com [NC] 
RewriteRule ^$ http://newdomain.com/ [R=301,L] 

RewriteCond %{HTTP_HOST} olddomain\.com [NC] 
RewriteRule ^author/([^/]+)/?$ http://newdomain.com/user/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} olddomain\.com [NC] 
RewriteRule ^add/?$ http://newdomain.com/submit [R=301,L] 
1

您是否嘗試過使用RedirectMatch

在htaccess文件在你olddomain.com文檔根目錄(它必須與您newdomain.com根不同):

RedirectMatch 301 ^/author/(.*)$ http://newdomain.com/user/$1 
RedirectMatch 301 ^/add(.*)$ http://newdomain.com/submit$1 
Redirect 301/http://newdomain.com/