[Solved] How to Hide parameters in URL in Symfony2


As explained in comments, the request needs something to identify the resource you want to fetch. But this has nothing to do with URL rewriting. If you want to display the slug of the resource instead of the id, do the following :

my_route:
    path:     /products/{slug}
    defaults: { _controller: MyBundle:Default:myaction}

Then, in MyBundle/Controller/DefaultController.php :

public function myactionAction(Request $request, $slug)
{
    $product = $this->getDoctrine()->getManager()->getRepository('MyBundle:Product')->findOneBy(["slug" => $slug]);
}

and when you want to create a link to this product, use

<a href="https://stackoverflow.com/questions/39059375/{{ path("my_route', {'slug': product.slug}) }}">link to the product</a>

solved How to Hide parameters in URL in Symfony2