Wednesday, March 9, 2016

How to Redirect Post in an Old Blogspot Domain to a New One

Few months back, I changed one of my blogs' domain to a new one. Right after changing the domain, I created another blog using the old domain so I still own that subdomain.

Recently, I received an email from Google Web Master Tools that I'm my old site has receiving a lot of soft 404's lately, meaning a lot of people are accessing my posts using the old domain that were indexed by Google.

Hence, I got the idea of redirecting the users when they access the old domain to the corresponding blog post in the new domain.

Here's the very simple trick.
  1. Go to your Blogger dashboard
  2. Go to Template and click the Edit HTML button.
  3. In the template code displayed in the textarea, look for the <head> tag.
  4. Add this very simple JavaScript code inside the head tag. 

<script type='text/javascript'>
  location.href = 'newdomain.blogspot.com'+window.location.pathname;
</script>


Basically, you just have to append window.location.pathname to your new domain so old posts can be mapped to their new address.

And viola, it redirects now!



The graph has been flat straight since I made the changes.

No comments:

Post a Comment