【问题标题】:Redirect all Http requests to Https in Laravel 5将所有 Http 请求重定向到 Laravel 5 中的 Https
【发布时间】:2016-05-13 16:14:53
【问题描述】:

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

【问题讨论】:

标签: php http laravel https laravel-5


【解决方案1】:

您可以使用 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.

要了解规则是如何工作的,请查看link

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

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

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

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

这个link 也会帮助你。

希望对你有帮助:)

【讨论】:

  • 我需要将页面从 http 重定向到 https。说,我有example.com/user,我需要将其重定向到example.com/user。我在 laravel 5 中尝试了上面的代码,它重定向到 index.php
【解决方案2】:

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

use Redirect;

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

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

然后重定向回来你可以使用这个

return redirect()->back();

检查这个link

【讨论】:

    猜你喜欢
    • 2014-06-30
    • 2013-11-26
    • 2017-04-30
    • 2014-11-17
    • 2011-05-04
    • 2016-11-17
    • 2019-06-18
    相关资源
    最近更新 更多