Redirecting Traffic to New Website

Simple Method to Use With Apache

Automatic redirection of traffic can sometimes be an important problem to solve. Here at our blog, we recently had to deal with the issue as we had two different addresses for our blog: www.theimclinic.com and www.theinternetmarketingclinic.com. Originally we set up the shorter name as a simple "alias" for the longer name, but this caused cross-site scripting errors with some of our JavaScript. What to do? You don't want to lose any indexing progress you've made with the shorter-name URLs, but you also can't leave them "in the wild". Forcing 301 redirects is the answer.

To set up 301 redirects for an entire "domain" the simplest solution for us was to make changes in our Apache configuration file. We do our own hosting, but if your primary hosting is on a VPS or even on some shared hosting setups, you can get access to your httpd.conf file to edit it, and this solution should work for you as well. I'm going to give you a short step-by-step description of the process, and then put up a brief screen-capture video of the work as well.

The changes you need to make are all in the VirtualHosts records in your configuration files. These techniques should work for both Apache 1.3 and Apache 2.X; the only difference might be which files the configurations are stored in. In most Apache 1.3 setups, they will be in the main httpd.conf file; in Apache 2.X setups, generally there will be a main httpd.conf file, but the virtual hosts will be set up in a separate file named httpd-vhosts.conf, which will be stored in the "extra" subdirectory under apache/conf. Assuming the domain you want to redirect is named "olddomain.com" and the one you want to redirect to is "newdomain.com", here are the edits to make:

  1. Remove any ServerAlias record for the "old" domain from the record for the "new" domain
  2. Add a VirtualHosts record for the "old" domain that contains the text shown below
  3. Restart Apache

<VirtualHost 192.168.1.10:80>
 ServerName www.olddomain.com
 ServerAlias olddomain.com
 Redirect permanent / http://www.newdomain.com/
</VirtualHost>

A few extra comments here: first, the IP address is just a standin; obviously yours will be different. Second, the extra ServerAlias entry is just to catch any oddballs that might try to access the site without the "www". Third, and this is crucial, do NOT forget the trailing "/" at the end of the newdomain URL. Once you restart the web server, any attempt to access any page under www.olddomain.com will be automatically redirected to the matching page under www.newdomain.com, using a "301" permanent-redirect. This is important because it will signal any search engines accessing the old URL that the new URL is in fact the same page it previously indexed at its new permanent address. This will prevent any loss in page ranking due to the move.

Video to Come!

Read more posts tagged with:

More posts filed under category: Website Basics

Like this post? Subscribe to our RSS feed and get loads more!