Symfony2 cloned routed

67 views Asked by At

I am trying to make 1 resource accessible by 2 different routes:

api_v1:
    type:     rest
    prefix:   /api/v1
    resource: "@AppBundle/Resources/config/routing.yml"

app:
    type:     rest
    prefix:   /
    defaults: { _format: html }
    resource: "@AppBundle/Resources/config/routing.yml"

But forever reason second route overrides the first. When I debug:router I get:

get_products    GET      ANY    ANY  /products.{_format}
post_products   POST     ANY    ANY  /products.{_format}
//etc...

But I am expecting

get_products    GET      ANY    ANY  /api/v1/products.{_format}
post_products   POST     ANY    ANY  /api/v1/products.{_format}
//etc...

get_products    GET      ANY    ANY  /products.{_format}
post_products   POST     ANY    ANY  /products.{_format}
//etc

What could I be doing wrong?

1

There are 1 answers

0
Wouter J On BEST ANSWER

You can't have 2 routes with the same name. In such cases, the second route overrides the previous defined route with the same name, exactly the behaviour you're describing.

It also seems very wrong to have 2 URLs point to exact the same resource. Use a (permanent) redirect to handle such cases.