Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop

    Secure Your Laravel Website: A Guide on How to Force Redirect HTTP to HTTPS for Better SEO

    Laravel Framework
    laravel php https redirect middleware
    1
    1
    229
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • root
      root Linux Help last edited by root

      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();
          }
      }
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post

      1
      Online

      3.6k
      Users

      1.3k
      Topics

      5.3k
      Posts

      • Privacy
      • Terms & Conditions
      • Donate

      © Copyrights and All right reserved Lanka Developers Community

      Powered by Axis Technologies (PVT) Ltd

      Made with in Sri Lanka

      | |