简体   繁体   中英

redirect all pages except root

I'm trying to separate out a WordPress site that has 4 specific blog sections built with custom post types to their own individual sites.

I have urls that look like:

example.com/site1/postname example.com/site2/postname etc

What I need to do is redirect all the posts under each site out to the new site while leaving the root page where it is.

So example.com/site1/postname becomes example2.com/postname

but example.com/site1/ needs to stay as example.com/site1/

And the same for the other 3 sites. Hope that makes sense.

I have this and it works great at redirecting the posts to the new site but it also redirects the root base as well and can't work out what to change to fix that.

RewriteEngine on
RewriteRule ^site1/(.*)$ http://www.example2.com/$1 [L,R=301]

To redirect everything except root of all 4 sites use:

RewriteEngine on

RewriteRule ^(site1|site2|site3|site4)/(.+)$ http://$1.com/$2 [L,NC,NE,R=301]

.+ after these sites will make sure to not to match root of these folders.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM