将所有 Http 请求重定向到 Laravel 5 中的 Https


Redirect all Http requests to Https in Laravel 5

我正在尝试将所有http请求重定向到Laravel 5中的https。Laravel 5 中是否有任何用于此操作的文档。 否则,请帮助我编写代码如何做到这一点。提前谢谢。

您可以使用htaccess文件从http重定向到https。将以下代码放入您的.htaccess文件中。

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
// change example.com with your website domain
// This will redirect all requests received on port 80 to HTTPS.

要了解规则的工作原理,请查看此链接。

在许多情况下,您也可以将这些行添加到要将 http 重定向到 https 的文件夹中名为 .htaccess 的文件中。

现在,当访问者键入 http://www.yoursite.com/mypage.htm 服务器将自动将http重定向到https,以便他们转到 https://www.yoursite.com/mypage.htm

注意:您还可以在配置文件或 .htaccess 文件中使用它,在 Apache 中将单个页面从 http 重定向到 http:

RewriteEngine On
RewriteRule ^apache-redirect-http-to-https'.html$ https://www.yoursite.com/apache-redirect-http-to-https.html [R=301,L]

此链接也将对您有所帮助。

希望它能帮助你:)

嘿,重定向您必须在顶部控制器中使用的任何页面

use Redirect;

在你的函数中,你可以像这样调用你想要的

return Redirect::route('foldername.filename') //ex - return Redirect::route('consignees.show')

并重定向回来,您可以使用这个

return redirect()->back();

检查此链接