Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 将旧域反向链接重定向到新域_Regex_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Regex 将旧域反向链接重定向到新域

Regex 将旧域反向链接重定向到新域,regex,apache,.htaccess,mod-rewrite,redirect,Regex,Apache,.htaccess,Mod Rewrite,Redirect,我即将在一个新域名上发布我的一个网站的更新版本,我想知道如何才能使旧的URL指向我的新网站,因为它有很多有价值的反向链接 我已经读过关于如何在.htaccess中进行301重定向的文章,但是我需要一些更高级的东西,因为我的一些url结构已经改变了。请参见下面的示例 olddomain.com newdomain.com - These will do just fine with the 301 redirect olddomain.com/author/username newdomain

我即将在一个新域名上发布我的一个网站的更新版本,我想知道如何才能使旧的URL指向我的新网站,因为它有很多有价值的反向链接

我已经读过关于如何在.htaccess中进行301重定向的文章,但是我需要一些更高级的东西,因为我的一些url结构已经改变了。请参见下面的示例

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

我不知道如何创建最后两个重定向,所以如果有人能为我指出正确的方向,那就太好了!:)

将此代码放入您的
文档\u 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]

您是否尝试过使用
重定向匹配

olddomain.com
文档根目录下的htaccess文件中(它必须与
newdomain.com
根目录不同):

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