Skip to main content
improved grammar and punctuation
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

If you want to set a controller for subdomain you just create a subdomain and handle it by DNS and web server, then set your subdomain path as root path for the subdomain on your web server, I mean both main domain and subdomain will be the same. and asAs you said like traditionally, you can create a route  / Controllercontroller for them .( becausebecause the codescode and modules are the same, so routes will be available on both).

and if you don't want your subdomains not available on your main domain, on your handler check domain name and if a request comes from the main domain don't return the result for it, maybe redirecting it to the homepage is not a bad idea) If you don't want the subdomains available on your main domain, on your handler check the domain name; if a request comes from the main domain, don't return the result for it. (Redirecting it to the homepage could be an idea.)

BUTBut the power of Symfony showshows itself to us, instead: Instead of manually handling the domain and subdomain route filtering there is an option for thaton the route, use host, as an example in the route definition.

   host:     "dev.example.com"

make that route available only for 'dev.example' host.

I thinkTake a look at look at HowHow to Match a Route Based on the Host couldfor further help you to achieve what you wantabout using that directive.

If you want to set a controller for subdomain you just create a subdomain and handle it by DNS and web server, then set your subdomain path as root path for the subdomain on your web server, I mean both main domain and subdomain will be the same. and as you said like traditionally create a route  / Controller for them .( because the codes and modules are the same so routes will be available on both).

and if you don't want your subdomains not available on your main domain, on your handler check domain name and if a request comes from the main domain don't return the result for it, maybe redirecting it to the homepage is not a bad idea)

BUT the power of Symfony show itself to us, instead of manually handling the domain and subdomain route filtering there is an option for that, host, as an example

   host:     "dev.example.com"

make that route available only for 'dev.example' host.

I think look at How to Match a Route Based on the Host could help you to achieve what you want.

If you want to set a controller for subdomain you just create a subdomain and handle it by DNS and web server, then set your subdomain path as root path for the subdomain on your web server, I mean both main domain and subdomain will be the same. As you said, you can create a route/controller for them (because the code and modules are the same, so routes will be available on both).

If you don't want the subdomains available on your main domain, on your handler check the domain name; if a request comes from the main domain, don't return the result for it. (Redirecting it to the homepage could be an idea.)

But the power of Symfony shows itself to us: Instead of manually handling the domain and subdomain filtering on the route, use host in the route definition.

   host: "dev.example.com"

Take a look at How to Match a Route Based on the Host for further help about using that directive.

Source Link
Yuseferi
  • 22.2k
  • 22
  • 118
  • 218

If you want to set a controller for subdomain you just create a subdomain and handle it by DNS and web server, then set your subdomain path as root path for the subdomain on your web server, I mean both main domain and subdomain will be the same. and as you said like traditionally create a route / Controller for them .( because the codes and modules are the same so routes will be available on both).

and if you don't want your subdomains not available on your main domain, on your handler check domain name and if a request comes from the main domain don't return the result for it, maybe redirecting it to the homepage is not a bad idea)

BUT the power of Symfony show itself to us, instead of manually handling the domain and subdomain route filtering there is an option for that, host, as an example

   host:     "dev.example.com"

make that route available only for 'dev.example' host.

I think look at How to Match a Route Based on the Host could help you to achieve what you want.