.htaccess用laravel重定向到ssl

时间:2022-01-16 19:39:18

I'm trying to use .htaccess to redirect to ssl on login url in laravel.

我正在尝试使用.htaccess在laravel中重定向到登录URL上的ssl。

Login url looks like: four.number.for.ip/auth/login

登录网址如下:four.number.for.ip / auth / login

If I use

如果我使用

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

It doesnt work. I have tried with

它不起作用。我试过了

%{HTTPS} !=on 

and it works. And also %{SERVER_NAME} returns ip/auth/login (i'm sure for that, as https!=on works)

它的工作原理。并且%{SERVER_NAME}返回ip / auth / login(我确定,因为https!= on works)

I can't see why this won't work.

我不明白为什么这不起作用。

1 个解决方案

#1


This should work for you. Let me know how it turns out.

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

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

Edit to give full rules. It should look something like this.

编辑以提供完整的规则。看起来应该是这样的。

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] 

#1


This should work for you. Let me know how it turns out.

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

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

Edit to give full rules. It should look something like this.

编辑以提供完整的规则。看起来应该是这样的。

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]