# redirectPlugin

**Kind:** Function

**Source:** [`src/helper/ssg/plugins.ts`](https://github.com/honojs/hono/blob/main/src/helper/ssg/plugins.ts#L55)

**Part of:** [Helper](subsystem-src-helper)

The redirect plugin that generates HTML redirect pages for HTTP redirect responses for status codes 301, 302, 303, 307 and 308.

When used with `defaultPlugin`, place `redirectPlugin` before it, because `defaultPlugin` skips non-200 responses.

```ts
// ✅ Will work as expected
toSSG(app, fs, { plugins: [redirectPlugin(), defaultPlugin()] })

// ❌ Will not work as expected
toSSG(app, fs, { plugins: [defaultPlugin(), redirectPlugin()] })
```

`redirectPlugin` generates HTML redirect pages for HTTP redirect responses with status codes 301, 302, 303, 307, and 308 during static site generation. Place it before `defaultPlugin`, because `defaultPlugin` skips responses that are not 200.

## Signature

```ts
function redirectPlugin(): SSGPlugin
```

**Returns:** `SSGPlugin`

## Diagram

```mermaid
graph LR
  A[Route response] --> B{Redirect status?}
  B -->|Yes| C[redirectPlugin]
  C --> D[Generate HTML redirect page]
  B -->|No| E[defaultPlugin]
  D --> E
```

## Usage

```ts
import { toSSG } from "hono/ssg"
import { defaultPlugin, redirectPlugin } from "./helper/ssg/plugins"

await toSSG(app, fs, {
  plugins: [
    redirectPlugin(),
    defaultPlugin(),
  ],
})
```

## AI Coding Instructions

- Use this plugin when application routes return HTTP 301, 302, 303, 307, or 308 redirect responses.
- Keep `redirectPlugin()` before `defaultPlugin()` in the `toSSG` plugin list.
- Do not place `defaultPlugin()` first; it skips non-200 responses before redirect pages can be generated.
- Preserve redirect response headers and destination handling when changing redirect-page generation.
