How can we use sub domains to access sub folders in Symfony.
The question is, how can I have a sub domain routed to a folder?
example.com -> example.com/*
app.example.com -> example.com/app/*
admin.example.com -> example.com/admin/*
api.example.com -> example.com/api/*
Some detailed examples:
url requested controller called route name
----------------------------------------------------------------
example.com/ example.com/ main_home
example.com/login example.com/login main_login
app.example.com/ example.com/app/ app_home
app.example.com/profile example.com/app/profile app_profile
So far hard coding each controller works
Symfony: @Route("/", name="app_home", host="example.com")
Symfony: @Route("/", name="sub1_home", host="sub1.example.com")
But I haven't found a way of hiding the sub folder. So to access the profile page you still need to go to app.example.com/app/profile. Which defeats the purpose of the subdomain having /app in the url.
And yes, obviously any subdomain would have the sub folders restricted in the whole app. So you couldn't have example.com/api/ because that would be reserved for api.example.com
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…