diff --git a/routing/redirect_trailing_slash.rst b/routing/redirect_trailing_slash.rst index 1826cb7ba38..5233b535fff 100644 --- a/routing/redirect_trailing_slash.rst +++ b/routing/redirect_trailing_slash.rst @@ -10,7 +10,7 @@ trailing slash to the same URL without a trailing slash Create a controller that will match any URL with a trailing slash, remove the trailing slash (keeping query parameters if any) and redirect to the -new URL with a 301 response status code:: +new URL with a 308 (*HTTP Permanent Redirect*) response status code:: // src/AppBundle/Controller/RedirectingController.php namespace AppBundle\Controller; @@ -27,7 +27,9 @@ new URL with a 301 response status code:: $url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri); - return $this->redirect($url, 301); + // 308 (Permanent Redirect) is similar to 301 (Moved Permanently) except + // that it does not allow changing the request method (e.g. from POST to GET) + return $this->redirect($url, 308); } } @@ -50,7 +52,7 @@ system, as explained below: { /** * @Route("/{url}", name="remove_trailing_slash", - * requirements={"url" = ".*\/$"}, methods={"GET"}) + * requirements={"url" = ".*\/$"}) */ public function removeTrailingSlashAction(Request $request) { @@ -65,7 +67,6 @@ system, as explained below: defaults: { _controller: AppBundle:Redirecting:removeTrailingSlash } requirements: url: .*/$ - methods: [GET] .. code-block:: xml @@ -92,20 +93,10 @@ system, as explained below: ), array( 'url' => '.*/$', - ), - array(), - '', - array(), - array('GET') + ) ) ); -.. note:: - - Redirecting a POST request does not work well in old browsers. A 302 - on a POST request would send a GET request after the redirection for legacy - reasons. For that reason, the route here only matches GET requests. - .. caution:: Make sure to include this route in your routing configuration at the