You are here: Tech News Technology Using Apache's mod_rewrite Redirection to Prevent Duplicate Site Content

Using Apache's mod_rewrite Redirection to Prevent Duplicate Site Content

As a site owner or webmaster, you want to do everything you can to optimize your site properly for search engines. It may seem odd, but a little technicality like having or not having the "www" in your site address can cause search engines to consider your site to be a duplicate of itself, hurting its search engine ranking. You need to redirect traffic using Apache's mod_rewrite to redirect site visitor traffic to a single web address.

Consider the following:

Your site can be accessed via either of the following URLs:

  • http://yoursite.com
  • http://www.yoursite.com

PROBLEM:

From a search engine's perspective, they are two different sites with exactly the same content. Search engines — Google in particular — will penalize you for this.

SOLUTION:

The solution is to redirect visiting traffic to a single URL using Apache's mod_rewrite. It's your choice as to which version to redirect to as the permanent URL. If you have an ecommerce site and your SSL Certificate is registered to the "http://www.yoursite.com" version, then it would make sense to redirect traffic to the version containing the "www".

Different server configurations require different methods. This article pertains to using an htaccess file and mod_rewrite directives on a Linux server running Apache.

1. Make sure your hosting company has enabled the mod_rewrite Apache module.

2. Create a text file named htaccess.txt and type in (or copy and paste) the following lines of code, depending upon which domain type you wish to redirect from and to:

Example 1 – Redirect domain.com to www.domain.com

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^www.yoursite.com$ [NC]

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

Example 2 – Redirect www.domain.com to domain.com

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^yoursite.com$ [NC]

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

3. Replace the "yoursite.com" in the above code with your actual domain name.

4. Upload the file to the public_html directory of your Linux server.

5. Rename the file from "htaccess.txt" to ".htaccess"

6. Done!

Now when search engine spiders visit your site to update their indexes, they will first crawl the .htaccess page and encounter the 301 redirect instruction sending them to the unified URL.

You can try testing the setup by entering one of the old URLs and seeing if you get redirected.

Joomla Templates and Joomla Extensions by JoomlaVision.Com
More in this category: « Prev Next »
Login to post comments

Services Quick Links

Location

Azurelink serves clients from all over the U.S. Our home office is in the rural farming town of Townsend, Massachusetts.

249 Wallace Hill Rd
Townsend, MA 01469

Contact Us

Clients, for technical support issues please login and submit a trouble ticket.
9 + 3 =