In this article, I will share with you how to make force redirect website URL HTTP to HTTPS in laravel. as you mark, sometimes we install SSL in our live laravel website and still not auto redirect it HTTPS. so, here I have seen to you how to resolve this issue with some simple steps.
open your .htaccess file and add the following 2 line code in your file.
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
open your app/Providers/AppServiceProvider.php file and make the following change. please don't use this option in your local. because after you make this change your laravel application not run on the local server. this option only works in live.
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// force redirect https.
\URL::forceScheme('https');
}
}
i hope you like this article.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com
How to make Custome Log System in Laravel?
In this article, I will share with you h...How to Get the Current Year using PHP
Use the PHP date() Function You can s...How to Create Model in Laravel 7 using Command?
In this tutorial,i will learn you give t...How to access laravel pagination protected object property?
Hello, everyone in this tutorials i will...How to replace a word inside a string in PHP
Use the PHP str_replace() func...