Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitb3984d0

Browse files
committed
[PR #26213 Document redirections with 307/308 HTTP status codes
1 parent5bb7c53 commitb3984d0

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

‎routing/redirect_in_config.rst‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,76 @@ action:
155155
Because you are redirecting to a route instead of a path, the required
156156
option is called ``route`` in the ``redirect()`` action, instead of ``path``
157157
in the ``urlRedirect()`` action.
158+
159+
Redirecting POST/PUT calls
160+
--------------------------
161+
162+
As default behaviour of both methods mentioned above results in sending
163+
response with ``301`` or ``302`` HTTP status codes, the following call will
164+
be made with use of HTTP request method. But it some scenarios it is
165+
expected or required that following call will be made with the same HTTP
166+
method, i.e. when initial call was ``POST`` one, then following one should
167+
be also ``POST`` not ``GET``. In order to achieve this both
168+
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction`
169+
and
170+
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::redirectAction`
171+
are accepting aditional switch called ``keepRequestMethod``:
172+
173+
..configuration-block::
174+
175+
..code-block::yaml
176+
177+
# config/routes.yaml
178+
179+
# ...
180+
181+
admin:
182+
path:/webhooks/foo
183+
controller:Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
184+
defaults:
185+
route:foo_webhook_handler
186+
permanent:true
187+
keepRequestMethod:true
188+
189+
..code-block::xml
190+
191+
<!-- config/routes.xml-->
192+
<?xml version="1.0" encoding="UTF-8" ?>
193+
<routesxmlns="http://symfony.com/schema/routing"
194+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
195+
xsi:schemaLocation="http://symfony.com/schema/routing
196+
http://symfony.com/schema/routing/routing-1.0.xsd">
197+
198+
<!-- ...-->
199+
200+
<routeid="admin"path="/webhooks/foo"> ``
201+
<defaultkey="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction</default>
202+
<defaultkey="route">foo_webhook_handler</default>
203+
<defaultkey="permanent">true</default>
204+
<defaultkey="keepRequestMethod">true</default>
205+
</route>
206+
</routes>
207+
208+
..code-block::php
209+
210+
// config/routes.php
211+
use Symfony\Component\Routing\RouteCollection;
212+
use Symfony\Component\Routing\Route;
213+
214+
$collection = new RouteCollection();
215+
// ...
216+
217+
$collection->add('admin', new Route('/webhooks/foo', array(
218+
'_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction',
219+
'route' => 'foo_webhook_handler',
220+
'permanent' => true,
221+
'keepRequestMethod' => true
222+
)));
223+
224+
return $collection;
225+
226+
Switching ``keepRequestMethod`` switch to ``true`` will result in sending
227+
response with either ``307`` (when ``permament`` switch is set to false) or
228+
``308`` (with ``permament`` being true) HTTP status code which will tell that
229+
HTTP request should be repeated with both request method and body being
230+
unchanged.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp