In this tutorial, i’ll show you how to force https in your laravel application. HTTPS helps keep your browsing safe by securely connecting your browser with the websites you visit. there are vairous SSL certificate provider like Comodo SSL, RapidSSL, DigiCert, Entrust Datacard and others that provide paid SSL Certificate. There are also free like SSL For Free and Let’s Encrypt.

SSL is a necessity, not only because it secure the website but also good for SEO. Google has confirmed that it uses HTTPS as a ranking signal when showing search engine results.

In Laravel, there are various methodes to force http request to https. Choose one of the methodes below.

Using the .htaccess file.

We have to make some changes in .htaccess file so that the application will run with https.

Note: Remember about clearing cache in browser (then htaccess will work correctly).


Using AppServiceProvider.

Navigate to the directory /app/providers/ and open AppServiceProvider.php place this code in the boot method:


Read Also  How to build Multiple Authentication in Laravel

Using Middleware.

In this method, we have to create middleware with this artisan commande: php artisan make:middleware HttpsMiddleware . Now place this code in the handle method.


No Comments

Leave a Reply

your email address will not be published. required fields are marked *