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 ;)