Domanda

I have searched a lot but I couldn't find the answer of my specific problem.

Currently all users redirect to https://www.mydomain.com if they type one of the following.

  • http://mydomain.com (Replace http to https and add www here)
  • http://www.mydomain.com (Replace http to https here)
  • https://mydomain.com (Append www here)

I have this code in my .htaccess for above conditions.

RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

I can't figure out how do I stop redirection of any subdomain. e.g. users shouldn't be redirect to https if type on of the following:

  • abc.mydomain.com (subdomain can be any name)
  • http://abc.mydomain.com

Any idea how to do this?

Thanks in advance for the help.

È stato utile?

Soluzione

This rule should work:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

Altri suggerimenti

try:

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 

kj

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top