W3cubDocs

/Symfony 4.1

RedirectController

class RedirectController

Redirects a request to another URL.

Methods

__construct(UrlGeneratorInterface $router = null, int $httpPort = null, int $httpsPort = null)
Response redirectAction(Request $request, string $route, bool $permanent = false, $ignoreAttributes = false, bool $keepRequestMethod = false, bool $keepQueryParams = false)

Redirects to another route with the given name.

Response urlRedirectAction(Request $request, string $path, bool $permanent = false, string $scheme = null, int $httpPort = null, int $httpsPort = null, bool $keepRequestMethod = false)

Redirects to a URL.

Details

__construct(UrlGeneratorInterface $router = null, int $httpPort = null, int $httpsPort = null)

Parameters

UrlGeneratorInterface $router
int $httpPort
int $httpsPort

Response redirectAction(Request $request, string $route, bool $permanent = false, $ignoreAttributes = false, bool $keepRequestMethod = false, bool $keepQueryParams = false)

Redirects to another route with the given name.

The response status code is 302 if the permanent parameter is false (default), and 301 if the redirection is permanent.

In case the route name is empty, the status code will be 404 when permanent is false and 410 otherwise.

Parameters

Request $request
string $route
bool $permanent
$ignoreAttributes
bool $keepRequestMethod
bool $keepQueryParams

Return Value

Response

Exceptions

HttpException In case the route name is empty

Response urlRedirectAction(Request $request, string $path, bool $permanent = false, string $scheme = null, int $httpPort = null, int $httpsPort = null, bool $keepRequestMethod = false)

Redirects to a URL.

The response status code is 302 if the permanent parameter is false (default), and 301 if the redirection is permanent.

In case the path is empty, the status code will be 404 when permanent is false and 410 otherwise.

Parameters

Request $request The request instance
string $path The absolute path or URL to redirect to
bool $permanent Whether the redirect is permanent or not
string $scheme The URL scheme (null to keep the current one)
int $httpPort The HTTP port (null to keep the current one for the same scheme or the default configured port)
int $httpsPort The HTTPS port (null to keep the current one for the same scheme or the default configured port)
bool $keepRequestMethod Wheter redirect action should keep HTTP request method

Return Value

Response

Exceptions

HttpException In case the path is empty

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.html