I am making an website which handles subdomains, i have setup an environmental variable called base_host and now i want to use this into the @route
annotation in Symfony 4.
i have tried sofar: @Route("/", name="homepage", host="{afdeling}.{domain}", defaults={"domain"="%env(base_host)%"}, requirements={"domain"="%env(base_host)%"})
but this give me an error: using %env(base_host)% is not allowed in routing configuration
i have also tried: @Route("/", name="homepage", host="{afdeling}.%env(base_host)%")
this did not work at all.
also what i have tried is: @Route("/", name="homepage", host="{afdeling}.{domain}", defaults={"domain"="%base_host%"}, requirements={"domain"="%base_host%"})
but this gives me the error message: The parameter "base_host" must be defined.
how can i achieve this?
Environment variables are not supported (yet) inside routes configuration. As workaround you can create a "proxy" container parameter to achieve it:
# app/config/config.yml <= Sf 3.4 >= config/services.yaml
parameters:
base_host: '%env(BASE_HOST)%'
Then use %base_host%
for any route option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With