.... Internet marketing resources, ecommerce web site design tutorials
  Taming the Beast - quality web marketing and ecommerce development services .... .

 

Return to web marketing and ecommerce articles index

Changing domain names  & preserving rankings - mod_rewrite

In a previous article, I outlined some tips that can save your traffic and rankings when you rename or move around a few files on your current web site, or change domain names - by implementing a .htaccess 301 redirect. That article also contains information on dealing with canonical issues (www vs. non-www listings in search engines).

The basic 301 redirect works very well in that scenario, where folder paths will remain the same, but what if you are changing your domain name and/or changing many folder names? Writing out dozens, hundreds or perhaps even thousands of basic 301 redirects would be very time consuming and the potential for errors is huge.

If you've been using your current domain name for several years, you have probably built up a great deal of brand awareness amongst your visitors,  some solid search engine rankings and other links pointing to your site. It would be a shame to lose all that hard work - but there is a fairly simple way and relatively safe option for a smooth and seamless transition through the use of  mod_rewrite and a .htaccess file.

Need to learn about  search engine ranking and optimization strategies or want to monitor the SEO health of your web sites (and those of your competitors)? One of the most comprehensive set of online search engine optimization tools around -  SEOMOZ.

What is mod_rewrite?

mod_rewrite is an Apache module which allows for the rewriting of URLs. This "redirection" is transparent to the end-user and requires no special software on the visitor's end. In the instance of changing your domain name, when you use mod_rewrite; the visitor who goes to your old domain will still see the old domain name in their browser address bar on the first page they visit, but will actually be viewing content under the new name. Using the mod_rewrite strategy is also very search engine friendly.

What is a .htaccess file?

When a visitor/spider requests a web page via any means, your web server checks for a .htaccess file if your hosting runs Apache - which is a very common web server. The .htaccess file contains specific Apache directives for certain requests, including security, redirection issues and how to handle certain errors.

Before you do anything...

If you're also moving servers as well as the domain name change; there's a variety of other issues you should consider first. Read our guide to moving servers before going ahead with the steps below for some tips for a smoother transition. It also contains some useful information regarding geotargeting issues.

Step 1 - check  your web host.

If you're not sure of the server software used by your hosting service, you'll need to check with them to ensure that they support the mod_rewrite module, otherwise this will not work.

Step 2 - Activate your new domain name.

Once you know for sure your host supports mod_rewrite; upload all your files to the account for the new domain name. Ensure that the file base structure and naming is exactly the same as it was under the old domain name.

Step 3 - create a .htaccess file

Creating a .htacess file can be done with a simple text editor such as Notepad. Ensure when you name the file that you precede htaccess with "." at the beginning of the file name. This file has no tail extension, the name should be just:

.htaccess

Step 4 - insert the syntax

Basic - domain name change

For a basic domain name change, where folder names haven't changed, simply copy these following lines into the file, replacing "new.com" with the new domain name. If you have an existing .htaccess file; keep a backup copy of it and then remove all other instructions from the file; except for these:

RewriteEngine On

RewriteRule ^(.*)$ http://www.new.com/$1 [R=301,L]

The Rewrite rule in this instance simply re-maps from old domain to new. Be aware that the old domain name will still appear in the browser window. To check to make sure you are viewing the content on the new domain, simply right-click over an image and select "properties" to view the path. Check your site thoroughly.

Advanced - domain name/folder change

If you are changing folder names, then the following lines should be used. The RewriteRule section of the following statement should be on a single line and you'll need a RewriteRule line for each folder change. There's no need to use the "RewriteEngine On" again if you have also used the basic RewriteRule in your .htaccess file.

RewriteEngine On

RewriteRule ^olddir/(.*)$ http://new.com/newdir/$1 [R=301,L] 

Save the file, upload it back into your web (old domain) in the root document directory. Test it out by typing in the old domain name. You should be instantly and seamlessly transported to the new domain; even if you have typed in a particular page address on the old domain you should see exactly the same page under the new domain. 

Effects on search engine spiders

The mod_rewrite strategy is probably the safest way to preserve your rankings. On the next spidering, the search engine spider won't actually read the .htaccess file, it's the server that generates the response based on the contents of .htaccess. The search engine spider recognizes the response from the server as valid. The "301" in the syntax means "moved permanently". 

In the next update, the old domain name should disappear and be replaced with the new one; but be aware this *could* take up to a couple of months - your current domain name may still show in listings; but anyone who clicks from the listing will still go to the new domain. 

If you do see some fluctuations in rankings initially during the transition, don't panic - this is pretty normal while backlinks are recalculated etc. - you could have a few nail-biting weeks. Also bear in mind that search engines operate according to their own rules and can change those rules and methods of operation at any time. Any change to your pages or lack thereof can have undesired effects. The mod_rewrite strategy is a case of "if you have to do it, this is the best way to go". 

It is very important though that you get your link partners to update their links to you if you will be deactivating the old domain name in the future. Once the domain name is de-activated, and therefore the .htaccess file, all the links from other sites will be useless and *that* could impact on your future rankings.

Need to learn about  search engine ranking and optimization strategies or want to monitor the SEO health of your web sites (and those of your competitors)? One of the most comprehensive set of online search engine optimization tools around -  SEOMOZ.

More on mod_rewrite

mod_rewrite is a very powerful tool; the above application is just one example of what you can achieve. For further documentation on mod_rewrite:

http://httpd.apache.org/docs/mod/mod_rewrite.html

Related learning resources

A guide to moving servers

Renaming or moving files? 301 redirect it! 

Michael Bloch
Taming the Beast
http://www.tamingthebeast.net 
Tutorials, web content, tools and software.
Web Marketing, Internet Development & Ecommerce Resources
____________________________

Copyright information.... This article is free for reproduction but must be reproduced in its entirety, including live links & this copyright statement must be included. Visit http://www.tamingthebeast.net  for free Internet marketing and web development articles, tutorials and tools! Subscribe to our popular ecommerce/web design ezine!

Click here to view article index 

Online meeting & webinar software review
Powerful, easy to use collaboration tools that can help improve your marketing sales and training efforts. Learn more about these services in this review & try a free trial!

The best shopping cart software
Our reviews of some of the best shopping carts around - free ecommerce solutions  through to premium services offering affiliate programs, marketing modules & online soft goods delivery.  Shopping cart software guide 

Autoresponder software/mailing list manager
 Read our beginners guide and reviews of all-in-one autoresponder & email marketing software solutions.

Credit card transaction fraud screening!  Effective fraud screening is an essential part of running an online businesses. Fraud transactions cost you money and can threaten your merchant account. Pick up a stack of transaction screening tips in this free guide! 

Need some advice/tools for writing/creating a web design, development or marketing proposal?

 

 

 

Home

 

Get paid cash taking online surveys - free to join online 
survey companies that will pay you cash for your opinion!

In Loving Memory - Mignon Ann Bloch

copyright (c) 1999-2011  Taming the Beast  Adelaide - South Australia 

Profile - Contact - Privacy - Consultants Portfolio 

Search Site - Terms of Service - Social/environmental