.htaccess 使用 laravel 重定向到 ssl

.htaccess redirect to ssl with laravel

我正在尝试使用 .htaccess 在 laravel 中登录 url 时重定向到 ssl。

登录 url 看起来像:four.number.for.ip/auth/login

如果我使用

RewriteCond %{SERVER_NAME} login
RewriteRule .* https://%{SERVER_NAME} [R=301,L]

没用。我试过

%{HTTPS} !=on 

而且有效。 还有 %{SERVER_NAME} returns ip/auth/login(我敢肯定,因为 https!=on 有效)

我不明白为什么这行不通。

这应该适合您。让我知道结果如何。

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/auth/login [NC]
RewriteCond %{HTTPS} !^on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

编辑给出完整的规则。它应该看起来像这样。

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/auth/login [NC]
RewriteCond %{HTTPS} !^on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [L]