htmler
htmler

Reputation: 380

how to redirect subdomain to non-www

I want to remove www. from start of my URL it tried this :

I have found this work for mydomain.com

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.mydomain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

If i use mydomain.net.in it doesn't work how to get it done?

RewriteCond %{HTTP_HOST} ^mydomain\.net\.in$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.mydomain\.net\.in)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

Upvotes: 2

Views: 135

Answers (1)

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

I am not sure why you first appending www and then removing try with below, it will work for both.

RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

Clear cache beforehand.

Upvotes: 1

Related Questions