Tech-Evangelist

Technical Articles, Musings and Opinions from Tech-Evangelist

  • Home
  • About
  • Guidelines
Previous article: Creating a Favorites Bookmark Image – Favicon.ico Icon
Next article: Google AdWords Campaign Management Tips

Setting up 301 Permanent Redirect on Apache Servers

February 27, 2006 By Jonathan - Copyright - All Rights Reserved

Sometimes a Web site owner wants to change the domain name for a Web site. Sometimes a site owner registers several related domain names and wants to point all of the domain names to a single Web site. A 301 redirect is the proper way to accomplish this.

If not done properly, a redirect can result in a mirror site penalty if multiple web sites are created under multiple domains. A mirror site penalty typically results in a significant reduction in rank for the secondary domain names, but there have been cases reported when the search engines reduced the rankings for all of the domain names, including the original domain name. For this reason, it is wise to avoid situations where a site is duplicated under multiple domain names.

The mirror site penalty has its roots in the unethical practice of some Internet pirates to copy the HTML code and content from a high ranking Web site and set up a duplicate site as their own. This would logically result in another high ranking site. There are also some site owners who believe that a duplication of their current high-ranking site under multiple domain names will give them the opportunity to commandeer several top positions for the same Web site under different domain names. The dilemma faced by search engines is pretty obvious when it is theoretically possible for a large, high-ranking site to grab all top ten positions for a single site, each under a different domain name. The mirror site penalty is therefore a good way to prevent this type of abuse.

For these purposes there is only one type of redirection that is recognized as legitimate by almost all search engines. This method is called a 301 Permanent Redirect. The 301 refers to the status code sent to the requester (a spider in this case) through the header that accompanies each page request. A 301 status code tells the search engine algorithm that a permanent URL or page name change has taken place, which should cause the search engine to change the URL currently listed for the page to the new URL at the redirected location. The 301 redirect is most commonly used when a site owner changes a site’s domain name or when individual pages names have changed. It can also be used to resolve or prevent situations that duplicate a site under multiple domain names.

On Apache servers, a 301 redirect can be set up though the .htaccess file found in the root directory. Note that the file name is really just a file extension. The .htaccess file allows a developer to override several server configurations and allows URL rewriting through the use of a program called mod_rewrite.

One unusual aspect of the .htaccess file is that it sometimes does not show up when using an FTP utility to view a site’s root directory. Because it designed to be hidden, settings in FTP utilities sometimes have to be changed to enable the viewing of hidden files. Display Hidden Files with WS_FTP or CuteFTP may help you to resolve this issue.

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^olddomainname\.com 
RewriteRule ^(.*)$ http://www.newdomainame.com/$1 [R=permanent,L]

redirect 301 /old-page.html http://www.domainname.com/new-page.html 

The first block of code would be used in the .htaccess file when an old or secondary domain name is pointed to a site. In this case, if olddomainname.com is pointed to the site and a spider follows an olddomain.com URL link to the site, the spider should receive the 301 status code and the new domain name, which should cause it to change the URL in its database. A user should see olddomainname.com resolve into newdomainname.com in the address bar in their browser.

The second block of code can be used when changing the name of an individual page. When a user or a spider follows a link to the obsolete page, old-page-name.html, the same result as outlined above should be observed. One nice aspect of the page level redirection is that multiple redirections can be placed in the .htaccess file to accommodate a number of changes.

It is very important to verify that a 301 redirect is being generated. In order to do this, you must view the HTTP header that accompanies the request for the new Web page. The header is an invisible file that requires the use of an HTTP header viewer in order to view this information. here is one popular header viewer, but others can be found if you simplay search for "HTTP header viewer". Simply enter the original URL in the input box and view the resulting information. Make sure that the HTTP Response Header information indicates that a 301 Moved Permanently status code response was received.

Be aware that not all hosting companies allow Apache overrides through the .htacces file, but most do. Also be aware that a mistake in the mod_rewrite rules can make a Web site non-functional, so be prepared with a backup copy of the original .htaccess file from your Web site just in case something does not work as expected and you have to copy the original version back to the server.

Filed Under: Web Site Development

Comments

  1. Dave Slade says

    December 28, 2008 at 4:41 pm

    Did you know that you can manually choose your domain page by using the google settings button in the googles master tools page?

  2. Doogie says

    December 29, 2008 at 7:50 am

    Hi Dave

    Yes. The Google Webmaster Tools method is the workaround for sites who cannot use the .htaccess file, such as those that are on Microsoft servers.

    If your site is on an Apache server, the method shown above is the correct way to standardize the URLs, because it works with all search engines and all the URLs in your site.

  3. B George says

    August 6, 2009 at 5:33 am

    Hi,

    I’m using a tool to crawl my web pages. And the tool says I’ve duplicate pages. The duplicates are below:

    1. http://www.lenvica.in/
    2. http://www.lenvica.in/index.php

    Is it necessary and possible to redirect (1) to (2)?

    Thanks,
    Biju.

  4. Doogie says

    August 6, 2009 at 4:29 pm

    Hi Biju

    You do not necessarily need a redirect. A redirect does not get to the root of the problem. The problem is the links to the home page using index.php.

    You just need to eliminate all links that contain index.php. All links to the home page throughout the site should be changed to <a href=”/”>Home</a> or <a href=”http://www.lenivica.in/>Home</a>. The first one is better to use if you are doing development work on your PC because it does not use a domain name and can be used on any development server.

    If you want to do a redirect, you will want to do the opposite, which means you should redirect (2) to (1). The version without index.php should be your standard URL for the home page because that is the version used in all links to your site.

Categories

  • Affiliate Marketing
  • CSS Tutorials
  • FileZilla Tutorials
  • Home Theater
  • Internet Marketing
  • Internet Technology
  • Kindle Tips
  • MySQL Tutorials
  • Online Auction Tips
  • Paint Shop Pro Tutorials
  • PHP Tutorials
  • Tech News
  • Thunderbird Tutorials
  • Video Production
  • Web Site Development
  • WordPress Tutorials
Content and images are copyrighted by Tech-Evangelist.com and others

Copyright © 2023 Tech-Evangelist.com - All Rights Reserved
Posted code samples are free to use. Do not reproduce or republish articles or content on another web site.

Privacy Policy : Terms of Use