Documentation/Container/Services/Redirect

Redirection

The Redirect service provides a method to redirect to an internal page or a full URL.

Since this service is based on the 'Location' header, it must be applied before any content is rendered. The redirection can be executed in a controller or middleware, for example:

// variant 1
use Hleb\Reference\RedirectInterface;
$this->container->get(RedirectInterface::class)->to('/internal/url/'status307);

// variant 2
$this->container->redirect()->to('/internal/url/'status307);

Additionally, the Redirect object can be obtained through dependency injection using the Hleb\Reference\Interface\Redirect interface.

To redirect to a route address by its name, use Redirect together with the Router service, which allows you to retrieve this address.

$this->container->redirect()->to(url('route.name'));
Cookies Router

Page translated: chatgpt 4-o
Back to top