Say I have 3 subdomains, sub1
, sub2
, and sub3
. I want to redirect all HTTP requests to sub1
and sub2
to use HTTPS, but I do not want sub3
to do any redirects.
I initially had the following when I had just sub1
and sub2
setup, which worked fine, but since I have sub3
now and it cannot be directed to HTTPS, it doesn't work anymore:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://${HTTP_HOST}%{REQUEST_URI} [L,R=301]
Have a condition to check for domain name:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(?:sub1|sub2)\. [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.