Reputation: 844
I have a website that rewrites a non www url to a www url.
Therefor this condition is used:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This code is basically "rewrite everything that doesn't start with www", because of the exclamation mark. The problem is that with this code a subdomain at my website, let's say subdomain.mysite.com is also rewritten and becomes www.subdomain.mysite.com.
I tried adding this to prevent the subdomain from being rewritten, but It doesn't seem to do the trick completely...
RewriteCond %{HTTP_HOST} ^subdomain\. [NC]
RewriteRule ^ http://subdomain.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
how can I rewrite my adress without affecting the subdirectory.
Upvotes: 0
Views: 45
Reputation: 45132
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 1