Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Remove www from URLs. (See related posts)

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]

Comments on this post

notme posts on Jul 10, 2006 at 11:51
In many cases www.doman.com and domain.com ARE different domains. Anyway, I think you can achieve this without mod_rewrite by simply doing

RedirectPermanent / http://domain.com/

in the <www.domain.com> Vhost section.

Using mod_rewrite has usually an impact on performance and honestly, I think the redirect approach is more elegant.
nothingless posts on Aug 26, 2006 at 16:58
Yes, but hosted in a shared enviroment, you don't akways have access to add stuff to Vhost - I know I don't. :) Thanks for the advice though!

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts