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:

Read More

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]

Related posts

1 comment

  1. 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.

Comments are closed.