如何从htaccess强制执行https



每次加载登录站点节点时,我都必须强制执行https。例如,http://www.mysite.com/sign-in 应始终强制实施到 https。

我尝试了多个版本,但没有一个有效。这是我第一次使用 .htaccess

这是我尝试过的:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} sign-in
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI}/$1 [R,L]

不应该在重写的URL中同时使用%{REQUEST_URI}$1

您可以尝试以下代码:

RewriteCond %{HTTPS} off
RewriteRule sign-in https://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R=301]

我用:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} /sign-in
RewriteRule !(.*)lbping(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

最新更新