Wednesday 30 October 2013

No WWW Using .htaccess

There are some clear benefits to removing the "www" from your URLs:
  • Shorter URLs
  • Prevention of Google search engine penalties for duplicate content
  • Less bandwidth usage if you have many links per page
Luckily, removing the WWW from your page URLs (and subsequent Google listings) can be done inside your .htaccess file so that you wont have to go into every page on your website and remove the "www" from your anchors.

The .htaccess Code

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
 
Conversely, if you'd prefer to use "www" in all of your URLs, you can code:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
 
Save some URL characters and remove WWW from your site!

No comments:

Post a Comment