Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess Redirect to HTTPS except subdomain

Tags:

.htaccess

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.

like image 674
Eyad Fallatah Avatar asked May 28 '12 19:05

Eyad Fallatah


2 Answers

To Exclude any Subdomain from https rewrite add

RewriteCond %{HTTP_HOST} !=/(.*?)/.example.com
like image 196
Metacowboy Avatar answered Nov 10 '22 07:11

Metacowboy


Add another RewriteCond before your RewriteRule:

RewriteCond %{HTTP_HOST} !=m.example.com
like image 21
lanzz Avatar answered Nov 10 '22 06:11

lanzz