Haren Sarma
Haren Sarma

Reputation: 2553

how to redirect all non https url to https but not subdomain

I have a domain having two subdomain, I want that if someone type www.example.com or http://example.com , he should redirect to https://example.com but in case of subdomain he shouldn't redirect, eg: if he type http://subdomain.example.com, he shouldn't go to https://subdomain.example.com. I am using below general htaccess code,

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

But this code is redirecting all trafic to https including subomain. please help me to write htaccess code which will not redirect subdomain to https:// but other all trafic to https

Upvotes: 0

Views: 93

Answers (1)

Ram Sharma
Ram Sharma

Reputation: 8809

I feel you should try the code below.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !=subdomain.example.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

if above rules not worked than try to replace the above rule with this one

RewriteRule (.*) https://%{HTTP_HOST}%1%{REQUEST_URI}

Upvotes: 0

Related Questions