Symfony2 with Fosuserbundle firewall redirect from subdomain to main domain

I have one Symfony2 app with 3 subdomains:


the %domain% parameters is :

I have setup routing like this :

    resource: "@DomainAppBundle/Controller/"
    type: annotation
    prefix: /
    host: "app.%domain%"

    resource: "@DomainApiBundle/Controller/"
    type: annotation
    prefix: /
    host: "api.%domain%"

    resource: "@DomainFrontBundle/Controller/"
    type: annotation
    prefix: /
    host: "%domain%"

    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

And security like this :

        pattern: ^/
        host: "%domain%"
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            always_use_default_target_path: false
            default_target_path: front

    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }
    - { path: ^/, roles: ROLE_USER, host: "app.%domain%" }
    - { path: ^/, roles: ROLE_USER, host: "api.%domain%" }

My subdomain app and api are secured like i want with working perfectly.

But if i'm not logged when i load directly, i'm redirected to I don't want to be redirect on the subdomain, i want the firewall redirect if not logged only on main

Can anyone help me for that ?

Thanks ;)


You just have to override the login route and use that in your main security configuration. Don't forget to add host partemerter to the new login path. I think this answer can help you:

Symfony 2 Login on main domain only

Need Your Help

VC++ Error - syntax error : 'constant' on a enum

c++ enums syntax-error

I am using a source code for stereo vision and it gives an error

Where to create method to use in templates in Symfony 2

symfony2 doctrine2 twig dql

In my template, I want to call a function that will display the total counts of of Employee in Company.Employee is related to Department, Department related to Company in one to many relationships....

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.