问题
My redirect in htaccess file successfully redirects example.com to https://www.example.com
but if I type: https://example.com in the address bar, I am not redirected.
Current code looks a bit like this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^example.local$
RewriteCond %{SERVER_NAME} !.cms.me$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Adding the www after the https:// does not work:
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
回答1:
This will also redirect https://example.com to https://www.example.com You need to have your rule like this.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]
Let me know how that works out.
来源:https://stackoverflow.com/questions/34634798/how-to-redirect-https-sitename-com-to-https-www-sitename-com