Redirect non-www and non-http to https

对着背影说爱祢 提交于 2020-12-25 01:08:53

问题


Yesterday I Installed SSL on the server. Since than I can't reach some pages.

www.example.com/amsterdam/shoes

example.com/amsterdam/

^ both do not redirect to https://, not even http://

www.example.com/amsterdam

^ does redirect to https://

How do I redirect all pages to HTTPS with www via .htaccess?


回答1:


RewriteEngine on


RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NC,L,R=301,NE]

This will redirect both http or non-www to https://www




回答2:


Use:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

OR you can try:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]


来源:https://stackoverflow.com/questions/38069945/redirect-non-www-and-non-http-to-https

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