Laravel Redirect HTTP to HTTPS via .htaccess

Laravel Redirect HTTP to HTTPS via .htaccess

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]

Recommended Laravel Tutorials

AuthorTuts Make

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *