0

How can I create duplicate routes?

I want to have SEO and user friendly routing like:

  • /{product.slug}
  • /{category.slug}

But how does Symfony know which one to render? It now defaults to the last definition.

7
  • /p/{product.slug} and /c/{category.slug} is user friendly enough, isn't? Commented Nov 6, 2016 at 10:45
  • @Federkun I prefer avoiding the unnecessary nested path since this is better for SEO. Commented Nov 6, 2016 at 10:46
  • I'm pretty sure that google doesn't mind, but if you really need to do it you can create a route like /{product_or_category} and then forward the request to ProductController or (if product is not found) CategoryController Commented Nov 6, 2016 at 10:50
  • 1
    /{product_or_category} isn't a good structure either: what if you have a category with the same name of a product? what would you render? Commented Nov 6, 2016 at 10:57
  • 1
    Have a look here: stackoverflow.com/a/10438844. I guess the edit part is what you need. Commented Nov 6, 2016 at 13:28

1 Answer 1

0

You can create you route with two variables:

/{type}/{slug}

type would be productor category

Or, if you want only one variable, you can adapt your function depending on the value passed by URL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.