Apache .htaccess automatic redirection to www subdomain (301 moved permanently)

June 5, 2009 by V-Teq · 2 Comments
Filed under: Apache .htaccess 

The easiest way to make automatic redirection (301 moved permanently) from sites without specified subdomain to www subdomain is to use .htaccess file (using Apache server of course).

Options +FollowSymLinks
 
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{HTTP_HOST} ^v-teq.com$ [NC]
	RewriteRule ^(.*)$ http://www.v-teq.com/$1 [R=301,L,QSA]
</IfModule>

It converts URL requests without subdomain to URLs with www subdomain. It handles even request with specific site location or some script-like ?id=10&q=search.. stuff. For example:

http://v-teq.comhttp://www.v-teq.com
http://v-teq.com/2009-06-05/…http://www.v-teq.com/2009-06-05/…
http://v-teq.com/?action=testhttp://www.v-teq.com/?action=test