Redirect WordPress Site (HTACCESS) to new domain, but with certain exceptions

I’m trying to figure out the best way to redirect a client site to a new blog. They have a WordPress installation, which they want to redirect to a new WordPress site. The issues are they want to redirect everything, but four posts, to the root of the new domain. The four posts have corresponding ones on the new blog, so

olddomain/setting-goals/ redirects to newdomain/setting-goals/

Read More

The same goes for three other posts, but I can’t put them here due to reputation rules.

My issue comes in how can I do the redirect of four posts to their corresponding ones on the new domain and also redirect everything else (including home page) to the root of the new domain?

A caveat is they want to still be able to access their WordPress admin panel on the old domain, so wp-login.php and the /wp-admin/ folder.

I tried this code in htaccess on top of the default WordPress redirect, but it didn’t work for me. I just wanted to see if I can get one of the redirects working correctly. It was just redirecting the setting-goals/ to the root of the new domain:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/setting-goals/ [NC]
RewriteRule ^setting-goals/(.*)$ http://www.newdomain.com/$1 [L,R=301]
RewriteRule (.*) http://www.newdomain.com? [R=301,L]

Related posts

1 comment

  1. You can use for 4 rules like below to redirect to their exact URL on the newdomain. Then redirect everything else if it’s not wp-login.php or wp-admin.

    RewriteEngine on
    
    RewriteRule ^(setting-goals)/?$ http://www.newdomain.com/$1 [L,R=301]
    RewriteRule ^(setting-goals2)/?$ http://www.newdomain.com/$1 [L,R=301]
    RewriteRule ^(setting-goals3)/?$ http://www.newdomain.com/$1 [L,R=301]
    RewriteRule ^(setting-goals4)/?$ http://www.newdomain.com/$1 [L,R=301]
    
    RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin(.*)?)$
    RewriteRule ^(.*)$ http://www.newdomain.com/? [R=301,L]
    

Comments are closed.