How to move a web page without losing search rankings using a 301 redirect
Sometimes it's necessary to move a web page, or even an entire site. This could be because you've changed your domain name. Perhaps you've migrated to a new content management system and the urls have changed, or perhaps you just want to point several domains at a single canonical page to take account of misspellings. This can cause issues with your search engine rankings and can annoy users who may start to get 404 "page not found" errors for their bookmarks and search engine results. Thankfully there is an easy solution to both problems with a 301 "page permanently moved" redirect.
The Problem
If your site has already been spidered by the search engines, changing your URL structure or domain name can cause problems both for your SEO and your users. The search engines wont be able to tell that your pages have moved and so will not know that the new URLs are actually just the old pages in a different place. Your page rank will drop as your inbound links will not point to the new content and your pages could even be classified as duplicate content and removed from the listing.
Also your visitors may find it annoying as their bookmarks will stop working and links in their search results could return 404 errors. If you operate a high traffic site this could lose you a lot of good will.
The Solution
Thankfully there is an easy solution. A 301 redirect can be set up to seemlessly redirect traffic to the new location. The status code 301 in an http header means that the page has been permanently moved to a new location. Search engines use this information to update their records. You will keep at least a portion of your search ranking and you new pages will not be classified as duplicate content. Web browsers use this information to redirect the user to the new location. This happens immediately and in the background so the user hardly notices it. If you're using Apache2 this is easy to do.
There are several ways to implement a 301 redirect depending on your requirements.
Moving a single a single URL
The Redirect command can be used to repoint a single url at a new one. The Redirect directive looks like this:
This directive will redirect any requests for /old/url/structure/item-1.html to the new location: /new/url/structure/item-2.html. Notice the first URL is not fully qualified while the second one is.
If you are using Apache2 with Virtual Hosts place this command at the bottom of the relevant virtual host file in your apache2/sites-available directory. For example, in the www.heavenlymedia.co.uk Apache2 Virtual Host file we have a number of page specific redirects set up which I created when we changed our content management system:
# /etc/apache2/sites-available/www.heavenlymedia.co.uk
#
<VirtualHost *>
ServerAdmin This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
ServerName www.heavenlymedia.co.uk
ServerAlias www.heavenlymedia.co.uk
# Indexes + Directory Root.
DirectoryIndex index.php index.html
DocumentRoot /var/www/www.heavenlymedia.co.uk/htdocs/
# 301 Redirects
Redirect 301 /services.html http://www.heavenlymedia.co.uk/services/services.html
Redirect 301 /internet-marketing/index.html http://www.heavenlymedia.co.uk/services/services.html
Redirect 301 /community.html http://www.heavenlymedia.co.uk/community/community.html
Redirect 301 /portfolio.html http://www.heavenlymedia.co.uk/values/values.html
Redirect 301 /contact.html http://www.heavenlymedia.co.uk/contact/contact.html
</VirtualHost>
If you are using Apache 1 then place the redirect line in your .htaccess file. Remember, as always, you will need to restart Apache to see the effects.
Redirecting all traffic from an old domain to a new domain with the same URL structure.
The RedirectMatch command allows you to use Perl style regular expressions with variables to do your matching. With the RedirectMatch command you can map requests from one domain directly onto another, so pages from one will be served out from the new domain. For example:
The .* in this expression means "match as many characters as possible in the request string. Putting it in brackets saves it as a variable called $1 which gets used later to generate the url onto which the request will be matched.
For example, using the above directive, a request to:
http://www.old-domain.com/path/item.html
would be mapped to:
http://www.new-domain.org/path/item.html
We use this type of redirect in The Heavenly Social. Originally we thought of calling this site Heavenly Developers, so to catch the small amount of traffic we still get to the old domain I set up this Apache2 virtual host:
# /etc/apache2/sites-available/heavenlydevelopers.com
#
<VirtualHost *>
ServerAdmin This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
ServerName heavenlydevelopers.com
ServerAlias heavenlydevelopers.com
RedirectMatch 301 (.*) http://www.heavenlymedia.co.uk$1
</VirtualHost>
This redirects all traffic from the old host to the new one while maintaining the current URL structure.
This is particularly useful when you want to allow visitors to omit the www from the start of your url, or when you wan't to redirect from, for example, yourdomain.net to yourdomain.com.
If you're using Apache 1 and don't have virtual hosts place this line in your .htaccess file. Remember you'll need to restart Apache to see the effect.
Redirecting all traffic to an new domain without preserving url structure
If you've abandoned an old site but want to keep your page rank and redirect visitors to your new site without preserving your URL structure you can do this too. Just omit the brackets and variable reference from the previous example. eg.
This will redirect all traffic from your current domain to the root page of your new domain. If you do this consider creating a custom landing page explaining why you have redirected the visitor and showing them how to find what they are looking for.
The Wrong way to do it - Why you should never use a meta refresh
The meta refresh tag is a meta tag which some developers put in the head section of their web pages. It's important for several reasons that you never ever use this tag. This tag looks like this:
This tag will play havoc with both your usability and your Search Engine rankings. For more information or if you need convincing see The Trouble with Meta Refresh - common search engine gaffes #1.
Last Updated ( Monday, 04 June 2007 )
















