# RedirectResponse

**Kind:** Interface

**Source:** [`packages/core/router/router-response-controller.ts`](https://github.com/nestjs/nest/blob/master/packages/core/router/router-response-controller.ts#L23)

**Part of:** [Core](subsystem-packages-core)

`RedirectResponse` represents the data required to issue an HTTP redirect from the router response controller. It pairs a destination URL with the HTTP status code that determines how clients should handle the redirect, such as `302` for temporary redirects or `301` for permanent redirects.

## Properties

| Property | Type |
|---|---|
| `url` | `string` |
| `statusCode` | `number` |

## Diagram

```mermaid
graph LR
  Router[Router Handler] --> ResponseController[Router Response Controller]
  ResponseController --> RedirectResponse
  RedirectResponse --> URL[url: string]
  RedirectResponse --> Status[statusCode: number]
  ResponseController --> HTTPRedirect[HTTP Redirect Response]
```

## Usage

```ts
import type { RedirectResponse } from './router-response-controller';

const redirectToLogin: RedirectResponse = {
  url: '/login?returnUrl=%2Fdashboard',
  statusCode: 302,
};

// Pass the redirect response to the router response controller.
responseController.redirect(redirectToLogin);
```

## AI Coding Instructions

- Always provide a valid redirect target in `url`; preserve or encode query parameters when building dynamic URLs.
- Use an appropriate HTTP redirect status code: `301`/`308` for permanent redirects and `302`/`307` for temporary redirects.
- Keep redirect construction within routing or response-controller logic rather than returning raw redirect objects from unrelated services.
- Validate or constrain externally supplied redirect URLs to prevent open redirect vulnerabilities.
