My project has a subdomain shop.example.com
and routing.yml
is using the host matching feature (requires Symfony >=2.2) as explained here:
example_shop:
resource: "@MyShopBundle/Controller/"
type: annotation
prefix: /
host: "shop.example.com"
example_front:
resource: "@MyFrontBundle/Controller/"
type: annotation
prefix: /
URL matching works just fine, but I have some trouble generating full/relative urls (linking the domain to the subdomain e viceversa):
<pre>shop_index: {{ url('shop_index') }}</pre>
<pre>shop_test: {{ path('shop_test') }}</pre>
<pre>front_index: {{ url('front_index') }}</pre>
<pre>front_test: {{ url('front_test') }}</pre>
When I run the above code from index.html.twig
of MyFrontBundle
(route example.com
):
shop_index: http://shop.example.com/app_dev.php/
shop_test: //shop.example.com/app_dev.php/test
front_index: http://example.com/app_dev.php/
front_test: http://example.com/app_dev.php/test
However the same code in index.html.twig
of MyShopBundle
(route shop.example.com
) produces:
shop_index: http://shop.example.com/app_dev.php/
shop_test: /app_dev.php/test
front_index: http://shop.example.com/app_dev.php/ <!-- wrong! -->
front_test: http://shop.example.com/app_dev.php/test <!-- wrong! -->
As you can see the problem is generating urls from the subdomain poiting to full or relative urls of the domain. How ca I solve this?
Since your front routes are not fixed to a domain like the shop routes, the url
function uses the current domain, as every domain matches to this routes. Try to fix down your frontend routes:
example_front:
resource: "@MyFrontBundle/Controller/"
type: annotation
prefix: /
host: "example.com"