12

I would like to redirect all none-https requests to https excepts requests to sub-domains. For example

http://example.com/  =>  https://example.com/
http://example.com/page  =>  https://example.com/page

But

http://m.example.com/  REMAINS  http://m.example.com/

This is what I have in my .htaccess, which redirects all requests (including sub-domians):

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I know that I have to add a condition before the RewriteRule but I am quite not sure about the syntax.

Eyad Fallatah
  • 1,799
  • 4
  • 21
  • 33

2 Answers2

21

Add another RewriteCond before your RewriteRule:

RewriteCond %{HTTP_HOST} !=m.example.com
lanzz
  • 39,901
  • 9
  • 84
  • 94
4

To Exclude any Subdomain from https rewrite add

RewriteCond %{HTTP_HOST} !=/(.*?)/.example.com
Metacowboy
  • 121
  • 2
  • 4