Reputation: 1164
I want to disable subdomains, except www, so this would not work anymore: subdomain.mysite.tld, but this would: www.mysite.tld
I also want to redirect from mysite.tld to www.mysite.tld, which I know how to do, but if have mysite.tld it won't redirect to www, instead it will throw a forbidden error...
RewriteCond %{HTTP_HOST} !mysite.tld$ [OR]
RewriteCond %{HTTP_HOST} !www.mysite.tld$
RewriteRule .* - [F]
RewriteCond %{HTTP_HOST} !^www
RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 2
Views: 1728
Reputation: 785471
Can you try:
RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.tld$ [NC]
RewriteRule ^ - [F,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 4
Reputation: 1086
To rewrite to www:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.tld[nc]
RewriteRule ^(.*)$ http://www.mysite.tld/$1 [r=301,nc]
Upvotes: 1