2014-04-23 163 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/