DEV Community

Ishaan Sheikh
Ishaan Sheikh

Posted on • Edited on

4 2

How to force HTTPS in Laravel

To force your website to load with HTTPS in Laravel you can add the following code in your route/web.php file.


<?php

use Illuminate\Support\Facades\URL;

if(app()->environment('production')){
    URL::forceScheme('https');
}

....
// Your routes here

Enter fullscreen mode Exit fullscreen mode

It is a one of doing it, of course there are other ways to do so. You can add one in the comments below.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more