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


Redirect an entire directory on a WP site to a new domain, with a few subdirectory exceptions

我正在尝试将WP站点上的整个目录重定向到新域上的目录,新域上存在一些子目录例外。

例如

Redirect /2012/ to newdomain.com/blog
Redirect /2012/subdirectory to newdomain.com/2012/subdirectory

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

#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规则之前