Redirect to "/login" if is not logged in Redirect to "/login" if is not logged in symfony symfony

Redirect to "/login" if is not logged in


You need to make the entire site closed off to non authenticated users by adding a rule to the access_control. However, ensure that /login is an exception to this rule, by putting the exception before it.

access_control:- { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }- { path: ^/, role: ROLE_USER }


add this as the last line of your access control:

- { path: ^/, role: ROLE_USER }

ROLE_USER means any user , you can use ROLE_ADMIN to restrict access to admins. You should add another routes to the list as well. There's a couple of more ways to do it in controller or your template using 'is_granted' method. For more information read the Symfony documentation on security.