Currently, I have a website (example.com). http to https redirect is working via my .htaccess file
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This website also runs on subdomains.
If someone goes to www.subdomain.example.com of the website, I want them to be redirected to https://subdomain.example.com .
Is it possible to achieve this with the htaccess file without impacting the http to https redirect that I have working for example.com?
Thanks!
Yes, you can add multiple conditions.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.subdomain\.example\.com$ [NC]
RewriteRule ^(.*)$ https://subdomain.example.com/$1 [R=301,L]
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
1: If the HOST is www.subdomain.example.com
, redirect to https://subdomain.example.com/
2: If its not https
, redirect to https
.
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.