Redirect all Old Links to a New Domain

This tutorial only applies if you are using Apache and have an .htaccess file. (If you’re using WordPress, you probably have one.)

At some point in your online life, you’re going to need to change the domain for a website. Maybe your business name changed or you’ve decided to rebrand your lifestyle blog or the myriad of other reasons why this might happen. Now you’ve got to redirect all old links to a new domain.

Situation

You want to keep the website as it is, you want all your old links to remain intact and working, but you want the new domain to be prioritized from an SEO perspective, and you want users/readers to quickly get acclimated to the new domain name and start using it.

Your 5 Minute Redirect Fix

  1. Make sure the old domain is pointed to the same hosting server that your website lives on. This should already be the case, of course. But I’m mentioning it because sometimes when a domain name is changed, people often take that as an opportunity to switch hosting providers.
  2. Open up the .htaccess file for your website and add this:
    # Redirect the site
    RewriteEngine On
    # Take care of www.oldwebsite.com
    RewriteCond %{HTTP_HOST} ^www.oldwebsite.com$ [NC]
    RewriteRule ^(.*)$ http://newwebsite.com/$1 [L,R=301]
    
    # Takes care of oldwebsite.com
    RewriteCond %{HTTP_HOST} ^oldwebsite.comm$ [NC]
    RewriteRule ^(.*)$ http://newwebsite.com/$1 [L,R=301]

    What’s this code doing? If someone types in www.oldwebsite.com/about, it will redirect them to www.newwebsite.com/about. If someone types in oldwebsite.com/about, it will redirect them to newwebsite.com/about. So it takes care of both the www situation and the standalone URL situation.

This is a much better solution than just forwarding your old domain to your new one. Why? Because it keeps all your old links intact. If someone ever linked to you in the past, those links will still work (provided you’ve kept the same link structure as it was in the past). This is great for accessibility and also for SEO. Over time, Google will pick up on the fact that the new domain is your primary domain and shift your SEO juice to the new one from the old. Win and win.

We’re creating a(n opinionated) course on WordPress Theme Development!

It’s going to be jam-packed (over 35k words!) and full of awesome information just like this tutorial for a budding WordPress theme developer. If you’d like to hear more about it, pop in your email address.

Awesome! We’ll send you updates and sneak peeks of the course! Plus, whenever we publish other handy tutorials, we’ll be sure to let you know.┬áNo spam, we promise.

It looks like you're already subscribed. Yay!