Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.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
Php 将WP站点上的整个目录重定向到新域,但有几个子目录例外_Php_Wordpress_.htaccess_Redirect_Mod Rewrite - Fatal编程技术网

Php 将WP站点上的整个目录重定向到新域,但有几个子目录例外

Php 将WP站点上的整个目录重定向到新域,但有几个子目录例外,php,wordpress,.htaccess,redirect,mod-rewrite,Php,Wordpress,.htaccess,Redirect,Mod Rewrite,我试图将WP站点上的整个目录重定向到新域上的目录,新域上存在一些子目录异常 e、 g 这就是我所拥有的不起作用的东西: #blanket redirect with exceptions RewriteCond %{REQUEST_URI} !^/2012/$ RewriteCond %{REQUEST_URI} !^/2012/(\/2012\/subdirectory1\/|\/2012\/subdirectory2\/|\/2012\/subdirectory1\/) RewriteRul

我试图将WP站点上的整个目录重定向到新域上的目录,新域上存在一些子目录异常

e、 g

这就是我所拥有的不起作用的东西:

#blanket redirect with exceptions
RewriteCond %{REQUEST_URI} !^/2012/$
RewriteCond %{REQUEST_URI}
!^/2012/(\/2012\/subdirectory1\/|\/2012\/subdirectory2\/|\/2012\/subdirectory1\/)
RewriteRule ^/?2012/(.+)$ http://www.newdomain.com/blog/ [L,R=301]

#redirecting the exceptions
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$
RewriteRule ^\/2012\/subdirectory1\/$
"http\:\/\/www\.newdomain\.com\/2012\/subdirectory1\/" [R=301,L]

谢谢

我想你只是想要一些简单的东西:

RewriteRule ^2012/$ http://www.newdomain.com/blog/ [L,R=301]
RewriteRule ^2012/subdirectory/?$ http://www.newdomain.com/blog/subdirectory/ [L,R=301]
或者可能:

RewriteRule ^2012/(.*)$ http://www.newdomain.com/blog/$1 [L,R=301]

这些规则必须在htaccess文件中的任何wordpress规则之前

谢谢您的回复!这仍然将所有2012/子目录重定向到newdomain.com/blog/,即使有第二条规则。还有其他想法吗?@user2763413第一条规则仅将请求重定向到
/2012/
,或将请求重定向到
/2012/子目录/
。没有别的,甚至没有
/2012/file.txt
。我确实使用了您提供的第二条规则:
重写规则^2012/(*)$http://www.newdomain.com/blog/$1[L,R=301]
它没有正确重定向“异常”。它们仍然像所有其他/2012/子目录一样被重定向。这有意义吗?@user2763413第二条规则会重定向所有内容,如果我没有解释清楚,前两条规则不会道歉。这是将
/2012/子目录1
重定向到
http://www.newdomain.com/blog
当我希望它重定向到
http://www.newdomain.com/2012/subdirectory1
。不过,我只希望在少数子目录中发生这种情况,其余子目录将被重定向到
http://www.newdomain.com/blog
RewriteRule ^2012/(.*)$ http://www.newdomain.com/blog/$1 [L,R=301]