Hasan Setiawan

Write, write, write give your wings on code!

Follow me on GitHub

Force https:// in Symfony 3

Sometimes, you want to secure some routes and be sure that they are always accessed via the HTTPS protocol. The Routing component allows you to enforce the URI scheme via schemes:

        
            // app/config/routing.php
            use Symfony\Component\Routing\RouteCollection;
            use Symfony\Component\Routing\Route;

            $collection = new RouteCollection();
            $collection->add('secure', new Route('/secure', array(
                '_controller' => 'AppBundle:Main:secure',
            ), array(), array(), '', array('https')));

            return $collection;