How to redirect https://sitename.com to https://www.sitename.com

浪子不回头ぞ 提交于 2020-01-07 03:00:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!