[英]redirect to HTTPS if not HTTPS by .htaccess
如果用户随附-example.com-www.example.com- http://example.com-http : //www.example.com,我想将用户重定向到HTTPS( https://www.example.com )
我已经在.htaccess上使用了此代码。 但不适用于www.example.com, http://www.example.com
# BEGIN SSL Redirect
RewriteEngine on
# force ssl
RewriteCond %{SERVER_PORT} ^80$
RewriteRule https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteCond %{HTTP_HOST} ^calbel\.com
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R,L]
# END SSL Redirect
有很多方法,请尝试以下一种方法:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
如果不是必须使用.htaccess,为什么不使用:
header('Location: '.$newURL);
最近,我遇到了以下代码中的相同问题,用于强制重定向到https
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
如果不
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
尝试如下
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www [OR]
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.