301 redirects for specific WordPress URL’s else 301 everything to homepage on new domain

I seem to be going around in circles with this at the moment which is becoming frustrating…

I am trying to 301 redirect numerous WordPress URL’s to their new equivalents on a new domain from the old domain’s .htaccess and for everything else, apply a sitewide redirect to the new domain’s homepage.

Read More

Every time I try and implement a redirect for the entire site, it seems to override any redirects for individual pages though. I can’t seem to get both ways to work.

Here is an example:-

#Sitewide
RedirectMatch 301 ^(.*)$ http://newdomain.com

#Individuals
RedirectMatch 301 /page1 http://newdomain.com/page-1/
RedirectMatch 301 /page2/ http://newdomain.com/page-2/
RedirectMatch 301 /dfgeds/ http://newdomain.com/lpojpohj/

And I have tried literally LOTS of approaches and methods which include:-

  • RedirectMatch 301
  • Redirect 301
  • RewriteRule
  • RewriteCond with RewriteRule

I am aware of complications trying to get .htaccess directives to work in WordPress websites but I have also tried placing rules above the defaults, below the defaults or with the defaults.

So far, I have not found anything that works for every instance I am after yet I am sure it must just be something obvious at play here.

  • Which directives should I be using?
  • Which order should they be in?
  • Where in the WordPress .htaccess should be positioned?
  • Have you got an example you could offer that you’d expect to work for me to test?

Related posts

Leave a Reply

1 comment

  1. You need to put your #sitewide redirect bellow #Individuals redirects so that it can not override your individuals requests,

    #Individuals
    RedirectMatch 301 /page1 http://newdomain.com/page-1/
    RedirectMatch 301 /page2/ http://newdomain.com/page-2/
    RedirectMatch 301 /dfgeds/ http://newdomain.com/lpojpohj/
    #Sitewide
    RedirectMatch 301 ^(.*)$ http://newdomain.com