A Blog about technology, linux, peer2peer, cool new downloads and software development.

Tuesday, November 24, 2009

how to add/remove www. from domain name in .htaccess


to add/remove www. with mod rewrite :
cd public_html
vim .htaccess

# remove www
RewriteEngine On

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


# insert www
RewriteEngine On

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

No comments: