Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c76cb15

Browse filesBrowse files
committed
minor #9286 Use 308 to ensure http method is preserved (greg0ire, javiereguiluz)
This PR was merged into the 2.7 branch. Discussion ---------- Use 308 to ensure http method is preserved 307 and 308 were introduced exactly to solve this issue. Commits ------- e21cf2f Minor change f8f6bda Added some minor explanation about 308 code 8549488 Use 308 to ensure http method is preserved
2 parents d57db81 + e21cf2f commit c76cb15
Copy full SHA for c76cb15

File tree

Expand file treeCollapse file tree

1 file changed

+6
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-15
lines changed

‎routing/redirect_trailing_slash.rst

Copy file name to clipboardExpand all lines: routing/redirect_trailing_slash.rst
+6-15Lines changed: 6 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 (*HTTP Permanent Redirect*) response status code::
1414

1515
// src/AppBundle/Controller/RedirectingController.php
1616
namespace AppBundle\Controller;
@@ -27,7 +27,9 @@ 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+
// 308 (Permanent Redirect) is similar to 301 (Moved Permanently) except
31+
// that it does not allow changing the request method (e.g. from POST to GET)
32+
return $this->redirect($url, 308);
3133
}
3234
}
3335

@@ -50,7 +52,7 @@ system, as explained below:
5052
{
5153
/**
5254
* @Route("/{url}", name="remove_trailing_slash",
53-
* requirements={"url" = ".*\/$"}, methods={"GET"})
55+
* requirements={"url" = ".*\/$"})
5456
*/
5557
public function removeTrailingSlashAction(Request $request)
5658
{
@@ -65,7 +67,6 @@ system, as explained below:
6567
defaults: { _controller: AppBundle:Redirecting:removeTrailingSlash }
6668
requirements:
6769
url: .*/$
68-
methods: [GET]
6970
7071
.. code-block:: xml
7172
@@ -92,20 +93,10 @@ system, as explained below:
9293
),
9394
array(
9495
'url' => '.*/$',
95-
),
96-
array(),
97-
'',
98-
array(),
99-
array('GET')
96+
)
10097
)
10198
);
10299
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-
109100
.. caution::
110101

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.