Symfony2 with Fosuserbundle firewall redirect from subdomain to main domain

I have one Symfony2 app with 3 subdomains:

  • domain.com
  • app.domain.com
  • api.domain.com

the %domain% parameters is : domain.com

I have setup routing like this :

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

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

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

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    host:"%domain%"

And security like this :

firewalls:
    main:
        pattern: ^/
        host: "%domain%"
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            always_use_default_target_path: false
            default_target_path: front
        logout:true
        anonymous:true

access_control:
    - { 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 http://domain.com/login working perfectly.

But if i'm not logged when i load directly http://app.domain.com, i'm redirected to http://app.domain.com/login. I don't want to be redirect on the subdomain, i want the firewall redirect if not logged only on main http://domain.com/login

Can anyone help me for that ?

Thanks ;)

Answers


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....