Andy Boyd


htaccess rewrite to remove www prefix

Posted in Web Stuff by andy on the April 3rd, 2007

If you are looking for a way to “force” website traffic to not use www., then here is an .htaccess rule you can use


RewriteEngine On
# If subdomain www exists, remove it
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

There are other useful .htaccess tips at the following URL:

http://corz.org/serv/tricks/htaccess2.php

Leave a Reply

You must be logged in to post a comment.