gpt4 book ai didi

php - Laravel 将 Http 重定向到 Https

转载 作者:可可西里 更新时间:2023-11-01 00:29:50 33 4
gpt4 key购买 nike

我们使用 Laravel 5。要将 http 连接重定向到 https,请使用中间件 HttpsProtocol。

namespace MyApp\Http\Middleware;

use Closure;

class HttpsProtocol {

public function handle($request, Closure $next)
{
if (!$request->secure() && env('APP_ENV') === 'prod') {
return redirect()->secure($request->getRequestUri());
}

return $next($request);
}
}

在我们的 4 个测试用例中,只有 1 个(最后一次重定向)正确工作。其他3个案例中间件添加url extra index.php。

http://www.aqualink.az/index.php ---> https://www.aqualink.az/index.php/index.php http://aqualink.az/index.php ---> https://aqualink.az/index.php/index.php https://www.aqualink.az/index.php ---> https://www.aqualink.az/index.php/index.php https://aqualink.az/index.php ---> https://aqualink.az/index.php

最佳答案

我用htaccess解决了

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

关于php - Laravel 将 Http 重定向到 Https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39249334/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com