You can combine two paths by specifying _defaults: { id: 1 }
in the directive _defaults: { id: 1 }
# app/config/routing.yml blog: path: /blog/{page} defaults: { _controller: AppBundle:Blog:index, page: 1 }
a source
Pages with /show
and /show/
paths are different paths, so it’s best to set up a redirect to links with a slash at the end, or vice versa, how you decide.
In principle, you can use the method that is in Symfony CookBook
1. Create a controller:
// src/AppBundle/Controller/RedirectingController.php namespace AppBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; class RedirectingController extends Controller { public function removeTrailingSlashAction(Request $request) { $pathInfo = $request->getPathInfo(); $requestUri = $request->getRequestUri(); $url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri); return $this->redirect($url, 301); } }
Add to the very end of the list of routes a new route:
remove_trailing_slash: path: /{url} defaults: { _controller: AppBundle:Redirecting:removeTrailingSlash } requirements: url: .*/$ methods: [GET]
a source