将所有无http请求重定向到https + www(子域除外)
问题描述:
I have a bit of problem here while creating .htaccess file for proper redirection. I need to redirect all requests to https with www except subdomains.
This is the scenario:
http://example.com-> https://www.example.com
https://example.com-> https://www.example.com
http://www.example.com-> https://www.example.com
http://subdomain.example.com-> http://subdomain.example.com[unchanged]
or
http://subdomain.example.com-> https://www.example.com/sites/subdomain
Any help is highly appreciated.
答
In the htaccess file in your document root, add this to the top:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]