In this tutorial, you will learn how to redirect HTTP to HTTPS your laravel website with .htaccess.

Sometimes, you need to secure your laravel web with an SSL certificate. When you apply ssl certificate. And hit the urls of the app’s website in brower with https. Then your website will show Secure. But will hit urls with http on the browser. Then it will not show.

Automatic HTTP to HTTPS will not be redirected after you apply SSL certificate.

But for this, you have to do some configuration in the .htaccess file of Laravel App. Then it will automatic redirect http request to Https in laravel web app.

Navigate to your laravel root directory and find .htaccess file. After that open .htaccess file and update the following codes into it:

# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#laravel

Laravel Redirect HTTP to HTTPS via .htaccess
36.20 GEEK