问题
Using .htaccess, I need to redirect all requests from
http://www.domain,
http://domain,
https://domain
to;
https://www.domain.com
How would I do this? I don't have any subdomains.
回答1:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
That will direct all HTTP requests to https://www.example.com as well as redirect https://example.com to https://www.example.com.
回答2:
Try this one...
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTPS_HOST} ^domain.com$
RewriteRule ^(.*)$ "https\:\/\/www\.domain\.com\/$1" [R=301,L]
来源:https://stackoverflow.com/questions/6085740/htaccess-redirect-all-requests-to-https-www