Hello Devs,
In this tutorial, we are going to learn how to force redirect http to https in laravel application.
Follow this step by step guide given below:
Create Middleware
php artisan make:middleware redirectSecureHttp
app\Http\Middleware\redirectSecureHttp.php
public function handle($request, Closure $next){
if (!$request->secure()) {
return redirect()->secure($request->path());
}
return $next($request);
}
app\Http\kernel.php
protected $middleware = [
....
\App\Http\Middleware\redirectSecureHttp::class,
....
];
I hope this example helps you.