Moving a Site with Apache Redirects

My boss, Paul Allen (the lesser) asked me to blog about how I redirected his entire blog site to new domain without losing traffic. So at the risk of boring some of my more technical readers, but also in the name of retaining my job, here goes. :)

Before the Move

First, the part I didn’t do. Before the old site could be redirected, the new site had to exist and look sharp. Blake created a mock-up of the new look and feel and sent it to XHTMLized, a great company in the UK that returned a working WordPress theme the very next day for $150. Mike installed the latest WordPress on the new domain and put Paul on a blogging freeze while he imported the database from the old domain.

List Links that Should Redirect

Once Mike was finished, I made a list of links to the old domain that should redirect to the new domain if clicked or pasted into the browser. I picked a link to each different page type that I could think of. Although yours may vary (depending on what type of site your moving and what kind of link structure your using), my list of old links looked like this:

Main
http://infobaseventures.com/blog/

Post
http://www.infobaseventures.com/blog/2006/02/16/transparent-companies/

Category
http://www.infobaseventures.com/blog/categories/companies-to-watch/

Archive
http://www.infobaseventures.com/blog/2006/01/

Syndication
http://www.infobaseventures.com/blog/feed/
http://www.infobaseventures.com/blog/comments/feed/

I emailed this list to myself so I could test each link out after the redirect. Be thorough when making your list so that you don’t lose readers (or traffic from important links) during the move. For instance, if you forget to redirect your feeds, plan on losing your most tech-savvy readers.

Use Consistent File and Directory Naming Structure

If you use a similar (or at least consistent) directory and filename structure on your new site, you should be able to write just a few redirect rules rather than one for every page. If you’re just copying an normal directory to a new location, you don’t have to do anything here. If you’re using a CMS like WordPress, make sure that your new site is using the same permalink structure. In WordPress this is configurable in “Options > Permalinks”. The end goal is to keep the URLs of each of your pages looking similar.

You can test whether a redirect will be simple by doing a find and replace on your link list, then testing the new links. In my example I replaced “infobasemedia.com/blog” with “paulallen.net”, then tested each link to make sure it brought me to the appropriate page on the new site. They did. If yours do too, your redirect will be easy. If they don’t, you should probably fix your new site and try again. Alternatively, you can do a redirect for each page type, but it will be more difficult. It may however be the desired effect, if the whole reason for redirect was to modify your directory structure without taking a hit in traffic.

Decide if you want “WWW” in your URL and Stand by Your Decision

After I tested my new links, I tested whether the new links also worked without the “www”. They did. This may seem counterintuitive, but for SEO purposes, you actually don’t want them both to work. Or better, you want one to be a server alias redirecting to the other so that links to either URL land on just one, which is good for Google Juice. Which should you choose? It doesn’t really matter as long as you’re consistent. Traditionalists like the “www”. Some newfangled whippersnappers don’t.

Since I didn’t do the server alias for paulallen.net (Mike did), I’ll show you the pertinent parts of virtual host configuration file for Provo Labs.


<ServerName www.provolabs.com>
DocumentRoot /var/www/html/www.provolabs.com
...


<ServerName www.provolabs.com>
ServerAlias provolabs.com
Redirect permanent / http://www.provolabs.com/
...

This makes it so that if you try to go to http://provolabs.com/, you will be redirected to http://www.provolabs.com/. Is this vital moving a website? No. But it’s nice, and it’s better setup the site properly before you start directing traffic to it. At the very least you should know whether you want to include the “www” so that you can redirect it to the one that you plan on ending up with.

Making the Redirect

So, after much testing, you should finally be able to make the redirect. This is actually very simple. You just want to test it beforehand to make sure it’s seamless for your readers.

Here’s the code I put in the .htaccess file of the old blog site.

# Redirect permanent /blog/ http://www.paulallen.net/

Pretty easy, huh? I clicked save and opened up my list of links that should work. But some didn’t. I quickly commented the redirect out and looked again. There were some mod_rewrites on the old site that needed to be deleted for it to work properly, a common problem having to do with the permalink structure. So I removed the offending code, saving it in a separate file for backup. With the next try, it all worked. There were only about 2 seconds of traffic lost in my first attempt, and even that landed on the new site –it just didn’t land on the right page at the new site.

Google Juice

This is all just guesswork, but one important thing to note here is that you should probably use the permanent redirect. This tells people to update their links to your pages. It also tells Google that links coming to your old address should be credited to the new one. Despite this, you will see your PageRank go to 0 because Google dings your new address for being new. Don’t worry about that; nobody cares but you. If the traffic and content is still there and all inbound links are landing (with a permanent redirect) on the right pages, your users are still happy and your PageRank should go back up with a little time. In the interim you will still probably still place fairly well in natural search results for Keywords that you have really targeted. And for traffic from paid results and links, your PageRank obviously doesn’t matter.

But if you have a for-profit site that sells seasonal products and you need the money to eat, you might consider doing the switch in a slow season. And if you can afford to have something decent on the new URL being indexed by Google even months before you make the redirect, that would probably help too. Again, this is guesswork.

Link Checker

Despite testing all the main page types, we still missed a small number of pages because we did a database dump and import rather than copying an entire directory. Overall, we did what we wanted to do, and under normal usage it would have been perfect. But we forgot to check the old blog’s document root for html files and directories that were created outside of the standard WordPress administration panel and were (therefor) not in the database. The omitted pages were insignificant enough that we would not have known immediately that they didn’t work. Luckily Mike decided to use a link checker (like the free one I mention here) to verify all the links on the new site worked. Sure enough, there were some broken links to content that should have been there, but wasn’t. So there’s a little clean up to do (even still), but chances are that none of his readers noticed.

Do it Right the First Time

Demming’s seventh rule of TQM is “Do it Right the First Time”. The same axiom applies all over in life, and it certainly applies here. If you can get your site setup in the right directory and the domain in the first place, you save effort and uptime down the road. So if you can, just do it right the first time. Pretty obvious, I know –but it does take a little foresight and planning.

Deepest Apologies

Well, hopefully that wasn’t the longest post you ever read. If it was I apologize, but you might not be in this mess had you exercised a little self-control earlier on. Despite it’s length, I hope that somewhere in this long mess of verboseness you found a little nugget of wisdom that will be helpful to you the next time you move a website between domains or otherwise. If not, it must be because you didn’t look hard enough. Try reading it again. :)

PS. Let me know if I missed anything.

9 Comments

  • By blake, April 13, 2006 @ 7:04 am

    This one is getting delicious’d! Submit this to digg!

  • By Neal, April 13, 2006 @ 10:26 pm

    Very thorough (and extremely helpful) tutorial Jordy. Thanks for documenting it.

  • By John, April 16, 2006 @ 11:24 pm

    Is there a reason you used the .htaccess file and not the httpd.conf file for the redirect?

  • By Jordy, April 17, 2006 @ 7:31 am

    @ John,

    Yes, Paul’s old site was hosted by a company that didn’t give us access to the httpd conf. This is typical with hosting companies. An .htaccess file give you access to the things you need, without allowing you to screw things up for others. Either place would have worked in this example though.

  • By Tom, June 6, 2006 @ 1:14 pm

    This is an interesting post — Paul Allen posted a little while later that his domain transfer had actually resulted in a lot of lost rankings, though. What’s the final outcome? Do you still endorse this walkthrough, or have you refined it based on your experience with paulallen.net?

  • By Jordy, July 20, 2006 @ 2:13 pm

    @ Tom:

    I stand by it.

    I think Paul’s problem was not unique to him; Google had just changed it’s algorythyms a little and a lot of people across the board saw thier number of indexed pages fall through the floor.

    The real testament to me is that if you look at the Alexa Charts for his former domain and compare them the the charts of his new domain at the time of the change, you’ll see that traffic really remained pretty steady, despite almost a month without posting. This means that redirects were working. Also the new domain’s PR is now clear back up to 6, a possibility that would be very improbable if links coming to his old site didn’t contribute to the PR of the new.

    Overall, I think Google rewards sites that do things right. Using a temporary redirect for aging purpuses may work, or may have worked, but it definatly won’t work in the future.

  • By Tom Dalton, July 27, 2006 @ 2:31 pm

    I agree with you. This tutorial fits with my experience and I would have been surprised to see it not work, as Paul originally suggested it hadn’t. You might want to get him to post an update about it, lest he inadvertently lead astray some of his faithful bloglings.

  • By Simon, February 16, 2007 @ 10:11 am

    Why not simply use a rewrite rule to redirect the whole website to the new one (that is providing the URL structure remains the same):

    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]

    Only scanned this post so not sure, but you seem to suggest permanently redirecting every single URL to the new one, and providing it’s the same, the above rule (in a .htaccess file) would do the same in a few lines of code.

  • By Nick Gully, April 30, 2007 @ 7:44 pm

    Thank you for a good quick explanation of Rewrite. I used it like a charm to convince search engine spiders where all my content had moved.

Leave a comment