1

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643
Vibhu
  • 157
  • 8
  • There are some related issues - not 100% - but useful http://stackoverflow.com/questions/5151112/how-to-redirect-https-domain-com-to-https-www-domain-com http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www – BillyBigPotatoes Mar 04 '14 at 00:02

2 Answers2

0

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Hey Anubhava, It didn't work. I am getting loop redirect error. – Vibhu Mar 04 '14 at 02:00
  • Anubhava, your code only work for www and no www. But it still doesn't stop redirection of subdomain. http://abc.mydomain.com still redirecting to https://abc.mydomain.com. I don't want my subdomain to redirect to SSL. – Vibhu Mar 04 '14 at 02:10
  • Yes I made a mistake, fixed it now. Try again – anubhava Mar 04 '14 at 02:11
0

try:

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

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

kj

kj_
  • 703
  • 4
  • 9
  • It doesn't work for subdomain. when I type abc.mydomain.com. It redirect it to https://www.mydomain.com – Vibhu Mar 04 '14 at 02:03