Skip to content

Commit d08221c

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: Using const `Response::HTTP_MOVED_PERMANENTLY` for redirect
2 parents 2525bd9 + 29c2bec commit d08221c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

controller.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()``
132132
and ``redirect()`` methods::
133133

134134
use Symfony\Component\HttpFoundation\RedirectResponse;
135+
use Symfony\Component\HttpFoundation\Response
135136

136137
// ...
137138
public function index(): RedirectResponse
@@ -142,8 +143,10 @@ and ``redirect()`` methods::
142143
// redirectToRoute is a shortcut for:
143144
// return new RedirectResponse($this->generateUrl('homepage'));
144145

145-
// does a permanent - 301 redirect
146+
// does a permanent HTTP 301 redirect
146147
return $this->redirectToRoute('homepage', [], 301);
148+
// if you prefer, you can use PHP constants instead of hardcoded numbers
149+
return $this->redirectToRoute('homepage', [], Response::HTTP_MOVED_PERMANENTLY);
147150

148151
// redirect to a route with parameters
149152
return $this->redirectToRoute('app_lucky_number', ['max' => 10]);

0 commit comments

Comments
 (0)