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

Comments

2 Responses to “Apache .htaccess automatic redirection to www subdomain (301 moved permanently)”
  1. The article is ver good. Write please more

  2. Rytis says:

    I think developers should me wiping out those www, not making them permanently. That point is doing that?

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!