In this tutorial you will learn about the Laravel Redirect HTTP to HTTPS using htaccess and its application with practical example.
In this Laravel Redirect HTTP to HTTPS using htaccess tutorial I’ll show you how to redirect http to https using htaccess file in laravel. In this tutorial, you will learn how to redirect HTTP to HTTPS your laravel website with .htaccess.
Laravel Redirect HTTP to HTTPS using htaccess
Sometimes, when you need to secure your laravel web with an SSL certificate. When you have applied ssl certificate to your laravel application. Then you are required to your existing http urls to https version of urls in order to secure access of your application. In laravel urls with HTTP will not be redirected automatically to HTTPS after you apply SSL certificate.
In laravel it is possible to redirect existing http links to https urls automatically with htaccess file. To do so 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:
1 2 3 4 5 6 7 8 |
# 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] |