Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default Login page in FOSUserBundle (Symfony)

I think that both the question and the answer here shouldn't be very complicated.

I have installed and configured the FOSUserBundle to use in a project with Symfony2.

What I need to know is where I tell the Security which page it has to redirect the user when they try to access to a forbidden url.

By default it is /login. But I'd like to change it to a more general /main.

Thanks in advance

like image 272
ElPiter Avatar asked Jan 16 '23 21:01

ElPiter


1 Answers

It's not done by FOSUserBundle, but the Security system in Symfony2. You need to set the following in security.yml:

firewalls:
    main:
        form_login:
            default_target_path: /path/to/redirect/to

EDIT:

Sorry, misread the question. Change login_path to /admin like so:

firewalls:
    main:
        form_login:
            login_path: /admin

This will redirect you to the /admin page - make sure the path works and isn't protected by the firewall. More info here.

like image 72
cvaldemar Avatar answered Jan 25 '23 15:01

cvaldemar