Redirect all traffic to HTTPS (Force SSL)

Submitted by zOxta - 2 years ago

If you want to redirect all HTTP traffic to HTTPS (SSL) you can use this method. However, note that this may NOT work out of the box if you are behind CloudFlare/load balancer/reverse proxy unless you set a trusted proxy, more info here: http://www.laravel-tricks.com/tricks/fix-ssl-in-laravel-4-when-server-is-behind-a-load-balancer-or-a-reverse-proxy

// add this to your filters.php file inside App::before() if it exists

App::before( function( $request )
{
    if( ! Request::secure() )
    {
        return Redirect::secure( Request::path() );
    }
});
comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks