我想将用户重定向到HTTPS( https://www.example.com ) 如果他们一起来 - example.com - www.example.com - http://example.com - http://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
答案 0 :(得分:0)
有很多方法,试试这个:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
答案 1 :(得分:0)
如果不强制使用.htaccess,为什么不使用:
header('Location: '.$newURL);
答案 2 :(得分:0)
最近我遇到了同样的问题,使用下面的代码强制重定向到https
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
如果不是
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
答案 3 :(得分:0)
尝试如下,
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www [OR]
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]