This is something I always (1) forget to do, and (2) forget how to do. Simply add this code (modified for your domain name, of course) to your .htaccess file.

This is important to implement for your search engine ranking. Google, for example, thinks www.domain.com is a different site from domain.com, and this can seriously impact where you rank in Google. There are other ways of doing this, but the below is the only one that doesn’t spit back a 500 error on my server, for some reason.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

If you want to force ‘www’ on the front end of your URL, switch it up with:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

[Via DZone Snippets]

Share the love:
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • Netvibes
  • Technorati
  • TwitThis

Subscribe to comments Comment | Trackback |
Post Tags: , , ,

Browse Timeline


blog comments powered by Disqus

Copyright ©2002-2010 Andrew Marconi. All Rights Reserved.
Wordpress theme heavily relies on "Modicus Remix" by Zidalgo (with some customization).