【问题标题】:Laravel redirection to httpsLaravel 重定向到 https
【发布时间】:2020-10-16 18:42:28
【问题描述】:

嗨,我有一个用 laravel 和这个地址 http://example.com/check/ 制作的应用程序。 我想重定向到 https 所以我创建了这个中间件

    <?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\App;

    class HttpsProtocol
    {
        /**
         * Handle an incoming request.
         *
         * @param  \Illuminate\Http\Request  $request
         * @param  \Closure  $next
         * @return mixed
         */
        public function handle($request, Closure $next)
        {
            if (!$request->secure()) {
                return redirect()->secure($request->getRequestUri());
            }
    
            return $next($request);
        }
    }

然后我添加了

    \App\Http\Middleware\HttpsProtocol::class

到受保护的 $middlewareGroups 中的 App/Http 中的内核

重定向似乎有效,但重定向到此地址https://example.com/check/check 具有重复的 URI(检查) 为什么 非常感谢

【问题讨论】:

  • 为什么不用.htaccess文件来重定向?
  • 我也试过,但其他 www.example.com/uri.... 不起作用....找不到页面

标签: laravel redirect https


【解决方案1】:

看起来您不需要附加请求 URI,这已经发生了,所以试试吧:

if (!$request->secure()) {
   return redirect()->secure();
}

【讨论】:

  • 它给了我这个错误 函数 Illuminate\Routing\Redirector::secure() 的参数太少,
  • 如果我写这个就行了!!返回重定向()->安全($request->getPathInfo());嗯,为什么 getpathinfo 不只返回 /check ?
猜你喜欢
  • 2015-04-08
  • 2023-03-24
  • 2018-02-02
  • 1970-01-01
  • 2015-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多