http://www.perlmonks.org?node_id=797673

mrc has asked for the wisdom of the Perl Monks concerning the following question:

I'm using mod_rewrite to virtually map to a local path.

path:
/home/user/subdomain.domain.com/

Rules:
RewriteEngine On RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+\.[^.]+)$ RewriteRule ^(.*) http://%1$1 [R,L] VirtualDocumentRoot /home/user/%0
RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+\.[^.]+)$ will redirect http://www.subdomain.domain.com to http://subdomain.domain.com, but I want the reverse. http://subdomain.domain.com redirected to http://www.subdomain.domain.com and 'www' url to remain unchanged.
Changing the rule to RewriteRule ^(.*) http://www\.%1$1 [R,L] will broke entire configuration. I have also tried to modify RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+\.[^.]+)$ in many ways, but I don't know how to solve it.
Any help would be greatly appreciated. Thank you!!