Web Hosting Talk







View Full Version : Apache .htaccess redirect problem


Tertsi
02-14-2007, 04:44 PM
What do I need to add to make it so that domain.com/sub requests would redirect to sub.domain.com and the below .htaccess file's code wouldn't overwrite it? (Note that I'm okay with modifying the below to only redirect http://domain.com/ to http://www.domain.com/ if required)

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

Just to make the above surely clear:
If I for example entered http://domain.com/sub or http://www.domain.com/sub/ in the browser I need it to redirect to http://sub.domain.com/