Reputation: 131
i am trying to forward all traffic to my subdomain via htaccess.
i am using that .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule (.*) http://sub.domain.com/$1 [R=301,L]
its working but when i directly write my root domain to the address bar like: http://domain.com it stays on that url. i also want root domain to force forward to sub.domain.com
how to do that? help me out please.
Upvotes: 0
Views: 1674
Reputation: 784898
You need to make starting www.
optional in %{HOST_NAME}
.
Use this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]
Upvotes: 4