force-https in laravel

    By: Thad Mertz
    2 years ago

    Here is how you force redirect from http to https

    Useing .htaccess

    RewriteEngine On
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    

    In Laravel go under "app/Providers/AppServiceProvider.php"

    and then inside boot method add

    \URL::forceScheme('https');
    

    or add below given code in AppServiceProvider and boot method

    if($this->app->environment('production'))
    {
       $this->app['request']->server->set('HTTPS','on');
    }