问题
How to write htaccess rules for redirect example.com to www.example.com and also we have number of subdomains for example subdomain.example.cpm so i need to redirect it to https://subdomain.example.com. but when i write htaccess rules it is going to loop. please send how to write conditions for this.
回答1:
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
# example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# http to https for subdomains
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
来源:https://stackoverflow.com/questions/20840669/how-to-write-htaccess-for-subdomain-redirection-to-https