Skip to content

Forcing or eliminating the WWW via htaccess

If you have a website and want to force www.domain.com Use the following .htaccess code

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

If you want to eliminate the www prefix like domain.com then use the following .htaccess code

RewriteEngine On<br />
RewriteCond %{HTTP_HOST} ^www\.(.+)$<br />
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]<br />
comments powered by Disqus