.htaccess - htaccess redirect domain to https, subdomain to http and www to non-www -


i’m trying that:

force https main domain.

http or https://www.domain.com  -> https://domain.com http or https://domain.com  -> https://domain.com 

but not subdomains

http or https://www.subdomain.domain.com -> http://subdomain.domain.com http or https://subdomain.domain.com -> http://subdomain.domain.com 

and removing www.

now have that:

rewritecond %{http_host} ^www\.(.*)$ [nc] rewriterule ^(.*)$ http://%1/$1 [r=301,l] rewritecond %{https} off rewriterule (.*) https://%{http_host}%{request_uri} [r=301,l] 

this redirects www non-www , http https not subdomains. subdomain remains www , https.

thanks

you can use these 2 rules:

# main domain rewritecond %{http_host} ^(www\.)?domain\.com$ [nc] rewritecond %{https} off [or] rewritecond %{http_host} ^www\. [nc] rewriterule ^ https://domain.com%{request_uri} [r=301,l,ne]  # sub domain rewritecond %{http_host} ^(www\.)?subdomain\.domain\.com$ [nc] rewritecond %{https} on [or] rewritecond %{http_host} ^www\. [nc] rewriterule ^ http://subdomain.domain.com%{request_uri} [r=301,l,ne] 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -