How to redirect from www.domain.com to domain.com

October 25th, 2008 § 0

Rewrite rule to redirect http://www.domain.com to http://domain.com on Apache server by editing .htaccess file.

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

OR

Rewrite rule to redirect http://domain.com to http://www.domain.com

RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Obviously you need to REPLACE domain.com and www.domain.com with your actual domain name.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Tagged: ,

§ Leave a Reply