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 /

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 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, so for instance /test/ would be redirected to If we added #moved to the end of that URL, we would end up with and that wouldn’t work. So we’ll need to make a bit of a fancier redirect:

RedirectMatch 301 /(.*)?$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 to,please update your feeds & links!

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.

7 Responses to Change domain, and warn your visitors

  1. Dorset Web Designer
    Dorset Web Designer  • 9 years ago

    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!

  2. Glenn Friesen
    Glenn Friesen  • 9 years ago

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

  3. Danny
    Danny  • 9 years ago

    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)..

  4. alya gafur
    alya gafur  • 9 years ago

    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. Wolter Tjeenk Willink
    Wolter Tjeenk Willink  • 9 years ago

    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.

  6. Ann Donnelly
    Ann Donnelly  • 9 years ago

    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 ๐Ÿ™‚

  7. Rhys
    Rhys  • 9 years ago

    That’s really cool! Great implementation. Been thinking about moving domain names, this is a great idea. ๐Ÿ™‚