Secure Your Laravel Website: A Guide on How to Force Redirect HTTP to HTTPS for Better SEO
-
In this article, i'll explain how to redirect HTTP to HTTPS in Laravel. Whether you're using Laravel 6, 7, 8, 9 or 10 we've got you covered!
We have to modify AppServiceProvider boot method, i also disable HTTPS redirect in local.
in app/Providers/AppServiceProvider.php.
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Pagination\Paginator; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { } /** * Bootstrap any application services. * * @return void */ public function boot() { if ($this->app->environment('production')) { \URL::forceScheme('https'); } Paginator::useBootstrap(); } }