Reputation: 25770
My site has a lot of subdomains(3rd and 4th levels), for example:
http://de.site.com/catalog
http://product.de.site.com
and I need to automaticaly redirect all domains with "www", for example
http://www.de.site.com/catalog
http://www.product.de.site.com
to url without "www":
http://de.site.com/catalog
http://product.de.site.com
Could you please help me with .htaccess rules for this case ? Please note that this rule must be applied only for 3rd+ levels of domains.
Upvotes: 0
Views: 100
Reputation: 784898
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
Upvotes: 1