text 在Laravel网站上启用SSL并启用强制HTTPS重定向:https://www.cloudways.com/blog/how-to-setup-https-ssl-certificate

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 在Laravel网站上启用SSL并启用强制HTTPS重定向:https://www.cloudways.com/blog/how-to-setup-https-ssl-certificate相关的知识,希望对你有一定的参考价值。

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); 
}
}
Then, apply this middleware to every request adding, setting the rule at Kernel.php file, like so:

protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',

// appending custom middleware 
'MyApp\Http\Middleware\HttpsProtocol'

];

以上是关于text 在Laravel网站上启用SSL并启用强制HTTPS重定向:https://www.cloudways.com/blog/how-to-setup-https-ssl-certificate的主要内容,如果未能解决你的问题,请参考以下文章

从启用 SSL 的 SharePoint 网站打开文件

markdown 在自定义PHP网站上启用SSL证书

网站怎么启用SSL安全证书,开启https协议?

如何启用SSL安全证书

网站如何启用SSL安全证书?

如何启用 (https) SSL 证书 AWS EC2 托管站点