Skip to content

Commit 8549488

Browse files
committed
Use 308 to ensure http method is preserved
The 307 and 308 status codes were introduced exactly to solve this issue.
1 parent 97a3616 commit 8549488

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

routing/redirect_trailing_slash.rst

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trailing slash to the same URL without a trailing slash
1010

1111
Create a controller that will match any URL with a trailing slash, remove
1212
the trailing slash (keeping query parameters if any) and redirect to the
13-
new URL with a 301 response status code::
13+
new URL with a 308 response status code::
1414

1515
// src/AppBundle/Controller/RedirectingController.php
1616
namespace AppBundle\Controller;
@@ -27,7 +27,7 @@ new URL with a 301 response status code::
2727

2828
$url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri);
2929

30-
return $this->redirect($url, 301);
30+
return $this->redirect($url, 308);
3131
}
3232
}
3333

@@ -50,7 +50,7 @@ system, as explained below:
5050
{
5151
/**
5252
* @Route("/{url}", name="remove_trailing_slash",
53-
* requirements={"url" = ".*\/$"}, methods={"GET"})
53+
* requirements={"url" = ".*\/$"})
5454
*/
5555
public function removeTrailingSlashAction(Request $request)
5656
{
@@ -65,7 +65,6 @@ system, as explained below:
6565
defaults: { _controller: AppBundle:Redirecting:removeTrailingSlash }
6666
requirements:
6767
url: .*/$
68-
methods: [GET]
6968
7069
.. code-block:: xml
7170
@@ -92,20 +91,10 @@ system, as explained below:
9291
),
9392
array(
9493
'url' => '.*/$',
95-
),
96-
array(),
97-
'',
98-
array(),
99-
array('GET')
94+
)
10095
)
10196
);
10297
103-
.. note::
104-
105-
Redirecting a POST request does not work well in old browsers. A 302
106-
on a POST request would send a GET request after the redirection for legacy
107-
reasons. For that reason, the route here only matches GET requests.
108-
10998
.. caution::
11099

111100
Make sure to include this route in your routing configuration at the

0 commit comments

Comments
 (0)