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,859
  • 4
  • 22
  • 34

2 Answers2

21

Add another RewriteCond before your RewriteRule:

RewriteCond %{HTTP_HOST} !=m.example.com
lanzz
  • 42,060
  • 10
  • 89
  • 98
4

To Exclude any Subdomain from https rewrite add

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