How to force redirect http to https in Laravel 5.5 ?

When i was working on my first laravel 5.5 application and i make it live and i want secure connection using ssl, i buy from hosting provider. But i was thinking how to redirect http to https of url in Laravel.

After research i found to force redirect http to https my website link. If you are using Laravel 5.5 then you can redirect http to https link using middleware. I would like to create middleware for redirect http to https link.

Here, we have to create Middleware, So simple create middleware on following path and then you have to register that middleware in Kernel.php file. So let's just follow:

Create HttpsProtocol Middleware:

Now we have to create "HttpsProtocol" middleware and we will write code of redirect http to https link. So here i written code for redirect and make only for production server. So let's create middleware.



namespace App\Http\Middleware;

use Closure;

class HttpsProtocol {

public function handle($request, Closure $next)


if (!$request->secure()) {

return redirect()->secure($request->getRequestUri());


return $next($request);




Next we have to register this middleware in Kernel.php file as bellow following code:



namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel




* The application's route middleware groups.


* @var array


protected $middlewareGroups = [

'web' => [




// \Illuminate\Session\Middleware\AuthenticateSession::class,










Ok, As above i added middleware, you can add this way and now you can check your all links.

I hope you found your best solution...

November 15, 2017 | 11219 Viewer | Category : PHPLaravelLaravel 5Laravel 5.5
Related Posts