Remove WWW prefix in your domain name, or vice versa

Jul 28, 2010 by d0rr    No Comments    Posted under: Web Development

I was doing some SEO for my site the other day when I came across some inconsistencies in my website URL. Some appears to be adorr.net while the rest are www.adorr.net.

Do note that this only applies to Linux hosting accounts.

This can be annoying for search engines listings, and even cause mismatching paths when using Google Webmaster Tools to submit sitemap.

This issue however can be easily fixed by modifying .htaccess, and I decided to go with shorter version of adorr.net without www

Below is how the first part of my .htaccess

* Remember to replace adorr.net with your own domain!

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

Do note that the code above is to rewrite all requests of www.adorr.net to adorr.net.

If you want it to be the other way round, use the following .htaccess instead

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

Cheers!



Related Posts with Thumbnails

Got anything to say? Go ahead and leave a comment!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>