How to redirect to home page after logout? How to redirect to home page after logout? symfony symfony

How to redirect to home page after logout?


Normally it is redirect to home. Check your security.yml config file.

firewalls:            default:                    logout:            path:   /logout            target: / #This is home url


On Symfony 4, by default, the logout action redirects to the / path. You can change the default behavior by setting the proper configuration parameter in the security.yml config file.

security:    ...    firewalls:        ...        main:            ...            logout:                ...                target: app_login # you can specify a hard coded URL path or a route name


The easiest way, to my humble opinion, is to simply do a redirection in your logoutAction (so in your controller), like this :

public function myLogoutAction(){    // Your logout logic    return $this->redirect($this->generateUrl('my_route'));}