If you want to skip the reading, you can also watch this video which I posted on Youtube with real project example, includes

  • Why I did not use domain forwarding from Godaddy.
  • Why to choose one plugin over another.
  • How to install & put a regular expression for 301 redirection.
  • How to avoid infinite redirection loop or too many redirects error.
  • Some final words on what to do with your old website & with the new one

Ok today we will be discussing a scenario where when we move our old WordPress website to a new domain/subdomain and want to redirect all the posts,pages,categories,images,login etc. links to the our new domain/subdomain without affecting our SEO.

Recently been working on a WordPress website project, were i need to move complete website been hosted on a old subdomain to another new subdomain. As we just do not want to simply edit the DNS records for this and want to keep the old website aside, this was a simple cloning job but Before making this change I need to address some SEO concerns first which I faced and will be discussing here and how i overcome this.

So here is what I’ve been trying to achieve:

  1. I have decided to create a new sub-domain for my future marketing decisions and move all my articles to this new subdomain from my older subdomain.
  2. I want all my post that is were previously been shared on various social media to still redirect all links to this new URL, so that if someone clicked on those old links will still able to read my articles instead of landing on a dead link. As old website is already getting a good amount of traffic, so in the process of enabling a new copy of the old website and deleting the old website will eventually hamper the SEO very badly.
  3. A simple forwarding a domain along with masking will not work in this case as I’ve already tried that and my major concern is there are already over 150 articles been written and shared on very social media gaining traffic on daily basis.
  4. I don’t want to go technical by editing .htaccess file and write redirection for each url, also as my website already using a security plugin which is already editing the .htacess file, I prefered not to edit it.
  5. I need to use regression expression with wildcards to overcome the issue of extra parameters been added by every social media on to the post been shared through my website so that i can save time writing 301 redirects for each of the articles urls, which also count any other dynamic links like archive or categories.
  6. Enabling & disabling links will be easier for me if involves any changes in future.

 

Let’s get started, how I did this:

Here I have my old website running on my subdomain “blogs.grenocity.com” which already getting a good amount of traffic, but recently I have decided to use new subdomain “news.grenocity.com” for my future marketing campaigns and promotions, moreover I want this new subdomain to serve as a complete news portal instead of servings just as a simple blog portfolio for my website.

As usual I copied the complete website over to the new subdomain so that now I have both copies running on two different subdomains.

After that I logged into the wordpress admin dashboard on to my old subdomain and disable the search engine visibility option so that search engine crawlers will not be able to access this website in the future again but I did not remove and Google Analytics Tracking codes just to reassure if I won’t be getting any new traffic on this old subdomain, also whenever I need to look and compare for the old traffic reports those will be still there.

I have decided to 301 redirect every article by using a plugin and manually what and all the redirects so that I will be completely sure that everything is is working perfectly fine. so I decided to look into various available options in WordPress repository for 301 redirects.

“one thing you need to make sure while installing or using any kind of redirection plugin that it must support use of regular expressions, so that you can use wildcards to redirect your urls”

I decided to use Redirection plugin by John Godley as its free and supports Regex for the results i intended to achieve.

After installing and activating the plugin will encounter some welcome screens like these..

[GALLERY]

 

Finally after clicking finished! you will see the plugin options page.

 

Select “Redirects” from the upper tab and Add New,

For my source URL I first select the Regex from the drop-down on right-hand side


, then i put this expression there.

/(.*)

by forward slash “/” means whatever string of characters comes after / which is my main domain URL (Old).

by dot star .* is the regular expression, the . means ‘any character’, and the * means any number of any characters and this is equivalent to saying “match whatever followed by any sequence of characters” comes after the URL which we defined. The bracket around the dot star tell redirection to capture the URL data.

In the target URL, enter your new domain URL follows by $1 character. Here the captured data from dot star will be replaced with the $1, so you get the idea right!

www.myolddomain.com/whatever-old-url

Here,
(.*) = whatever-old-url = $1

So, will becomes
www.mynewdomain.com/whatever-old-url

I found this very helpful as while sharing links on various social media’s add some extra parameters in the shared URL’s. So by redirecting links this way you need not to worry about those extra parameters.

 

a word of precaution here, as in WordPress if you ever tried to redirect with .htaccess file (I once did this while setting up redirect for SSL EV certificate on a client website) it falls into an indirect loop or too many redirects error for wp-admin. Long story short, if you do not want to be in such kind of a situation, just add carat ^ character before starting of your old URL, like this

^/(.*)

this tells the regular expression that it only applies when matched at the start of the URL. This prevents it matching elsewhere in the URL, and stops the infinite redirect such as repeating file names (eg. index.php or login.php)