Change domain, and warn your visitors

When you change domains, for instance using my moving WordPress to a new domain guide, you’ll usually redirect your visitors with something looking like this:

Redirect 301 / http://new.example.com/

The only issue with this is that people might not notice that you’ve moved to a new domain, and thus might not update their links to you. As Matt Cutts confirmed a while back that 301 redirects do not pass full PageRank, and they seem to take a hell of a time to kick in these days, that’s somewhat of an issue: we’d rather have people update their links.

The proper redirect

So we want to tell people that you’ve moved to a new domain, but only people who came through old links to your site. And we still want to keep that 301 redirect in place, to preserve as much of the value from the old site as we can.

So, what if we redirected to http://new.example.com/#moved? The search engines don’t care about anything from the hash onwards, so the value of the redirect would still be maintained. We could then use javascript to detect the value of the hash tag, and display a notice to our visitors.

There’s an issue with that as well though: with the redirect 301 / line above, we redirected everything after /, to new.example.com/, so for instance /test/ would be redirected to new.example.com/test/. If we added #moved to the end of that URL, we would end up with new.example.com/#moved/test/ and that wouldn’t work. So we’ll need to make a bit of a fancier redirect:

RedirectMatch 301 /(.*)? http://new.example.com/$1#moved

That should work. Notice though that when you have code in place adding a / to the end of your URL’s if not existent, that code should conserve any hash tags in the URL.

Showing the domain move message

So now, let’s move on to the javascript part to actually show people a “we’ve moved” message, which is actually pretty simple. You create a div with the message you want to show, and put it in your footer, something like this:

<div id="domainmovemsg" style="display: none;">
  We've moved from old.example.com to new.example.com,please update your feeds & links!
</div>

As you can see, we default it to display: none; so not everybody sees it, and then you add this tiny snippet of javascript, also in the footer of your page, after you’ve loaded the div above:

if (document.location.hash == '#moved') {
  document.getElementById('domainmovemsg').style.display = 'block';
}

Example code

I’ve coded an example of this with some more styling etc., which you can find here. If you want to see it in action immediately, you’ll have to click this link.

Tags:


Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

7 Responses

  1. RhysBy Rhys on 9 June, 2010

    That’s really cool! Great implementation. Been thinking about moving domain names, this is a great idea. :)

  2. Ann DonnellyBy Ann Donnelly on 9 June, 2010

    I’m using 301 directs a lot lately with a lot of sites upgrading from static html to WordPress. I’ll have to try this out on these where the domain isn’t changing but URLs are. Thanks — it’s a good idea to make it perfectly clear to visitors. There’s always at least one that will get really confused when something like this occurs. Always thought it be great if there was a plugin for this sort of thing :-)

  3. Wolter Tjeenk WillinkBy Wolter Tjeenk Willink on 9 June, 2010

    Nice tip Joost. Great to use on individual pages instead of complete domain switches as well, i.e. when you have a lot of articles with deeplinks to it and you decide to create an update or transfer link value from old posts to more recent posts about the same subject.

    would be a great WordPress plugin feature by the way.

  4. alya gafurBy alya gafur on 10 June, 2010

    This articles help me to find out good information about moving domain name. Its helpfull.
    But i was still confuse what is big different between redirect (permanent 301) domain directory and sub domain. What best for redirect, sud domain or web directory? Sorry for asking, Thanks :)

  5. DannyBy Danny on 10 June, 2010

    Very nice tip, never thought of it! Implementing it right now, with some added JQuery slide effect it evens looks kind of awsome.

    BTW, this textarea extends the layout of your website (using FF)..

  6. Glenn FriesenBy Glenn Friesen on 14 June, 2010

    Excellent forethought. Just excellent. I’m definitely going to remember your advice when I set up future redirects. Thanks for the tip!

  7. Dorset Web DesignerBy Dorset Web Designer on 18 June, 2010

    Changing domain names can be a frightening prospect. Especially with High Ranking, High Traffic website. Being a WordPress user, I use .htaccess file to do 301 redirects. Many web hosts also offer easy ways to setup redirects through your CPanel (if your using Linux).

    Google also offers a really easy way of altering what domain they index and also allows you to permanently redirect your website to a new domain.

    Sometimes it’s worth the risk if you believe the new domain name will have longer term benefits!