0

I am trying to redirect an entire directory on a WP site to a directory on a new domain, with a few subdirectory exceptions that exist on the new domain.

e.g.

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

This is what I have that is not working:

#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]

Thanks!

4

1 回答 1

1

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

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

于 2013-09-11T14:45:27.097 回答