how to redirect all non https url to https but not

2019-09-06 19:22发布

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

标签: php .htaccess
1条回答
别忘想泡老子
2楼-- · 2019-09-06 20:03

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}
查看更多
登录 后发表回答