RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
它将使用相同的请求和GET变量将任何非https连接重定向到https。
如果您的网站通过CloudFlare运行,您的https请求可能实际上以纯文本(http)打到您的服务器,这很令人困惑。
对于这种情况,你可能需要这样的一个http来https重定向:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
如果您正在运行nginx,请转至:
Admin Level -> Custom Httpd Config -> domain.com
并在令牌| CUSTOM4 |中添加:
|*if SSL_TEMPLATE="0"|
return 301 https://$host$request_uri;
|*endif|











