> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/stormkit-io/stormkit-io/llms.txt
> Use this file to discover all available pages before exploring further.

# Redirects

> Manage URL redirects and path rewrites for your Stormkit environments

The Redirects API allows you to configure URL redirects and path rewrites at the environment level.

## Get Redirects

<ParamField path="GET /v1/redirects" type="endpoint">
  Retrieve all redirect rules for an environment.
</ParamField>

### Response

<ResponseField name="redirects" type="array">
  Array of redirect objects

  <Expandable title="Redirect Object">
    <ResponseField name="from" type="string">
      Source path or pattern (supports wildcards)
    </ResponseField>

    <ResponseField name="to" type="string">
      Destination path or URL
    </ResponseField>

    <ResponseField name="status" type="number" optional>
      HTTP status code (200, 301, or 302)
    </ResponseField>

    <ResponseField name="assets" type="boolean" optional>
      Whether to include assets in wildcard redirects
    </ResponseField>

    <ResponseField name="hosts" type="array" optional>
      Array of hostnames to apply this redirect to
    </ResponseField>
  </Expandable>
</ResponseField>

<CodeGroup>
  ```bash Request theme={null}
  curl -X GET \
    -H 'Authorization: <api_key>' \
    -H 'Content-Type: application/json' \
    'https://api.stormkit.io/v1/redirects'
  ```

  ```json Response theme={null}
  {
    "redirects": [
      {
        "from": "*",
        "to": "index.html",
        "status": 200
      },
      {
        "from": "/old-page",
        "to": "/new-page",
        "status": 301
      }
    ]
  }
  ```
</CodeGroup>

***

## Set Redirects

<ParamField path="POST /v1/redirects" type="endpoint">
  Update redirect rules for an environment.
</ParamField>

<Warning>
  This endpoint replaces **all** existing redirects. Include all redirect rules you want to keep.
</Warning>

### Request Body

<ParamField body="redirects" type="array" required>
  Array of redirect objects to set

  <Expandable title="Redirect Object">
    <ParamField body="from" type="string" required>
      Source path or pattern. Supports wildcards (\*)
    </ParamField>

    <ParamField body="to" type="string" required>
      Destination path or URL
    </ParamField>

    <ParamField body="status" type="number" default="200">
      HTTP status code: `200` (rewrite), `301` (permanent redirect), or `302` (temporary redirect)
    </ParamField>

    <ParamField body="assets" type="boolean" default="false">
      Apply wildcard redirects to asset files (files with extensions)
    </ParamField>

    <ParamField body="hosts" type="array">
      Limit redirect to specific hostnames
    </ParamField>
  </Expandable>
</ParamField>

### Response

<ResponseField name="redirects" type="array">
  The updated array of redirect objects
</ResponseField>

<CodeGroup>
  ```bash Request theme={null}
  curl -X POST \
    -H 'Authorization: <api_key>' \
    -H 'Content-Type: application/json' \
    'https://api.stormkit.io/v1/redirects' \
    -d '{
      "redirects": [
        {
          "from": "/old-path",
          "to": "/new-path",
          "status": 301
        },
        {
          "from": "*",
          "to": "index.html",
          "status": 200
        }
      ]
    }'
  ```

  ```json Response theme={null}
  {
    "redirects": [
      {
        "from": "/old-path",
        "to": "/new-path",
        "status": 301
      },
      {
        "from": "*",
        "to": "index.html",
        "status": 200
      }
    ]
  }
  ```
</CodeGroup>

***

## Redirect Types

### Path Rewrite (Status 200)

Serve content from a different path without changing the URL:

```json theme={null}
{
  "from": "*",
  "to": "index.html",
  "status": 200
}
```

This is commonly used for single-page applications to handle client-side routing.

### Permanent Redirect (Status 301)

Redirect permanently to a new URL:

```json theme={null}
{
  "from": "/old-page",
  "to": "/new-page",
  "status": 301
}
```

Use for moved content that won't be returning to the old URL.

### Temporary Redirect (Status 302)

Redirect temporarily to a different URL:

```json theme={null}
{
  "from": "/maintenance",
  "to": "/under-construction",
  "status": 302
}
```

Use when content is temporarily moved but will return to the original URL.

***

## Advanced Patterns

### Wildcard Redirects

Use `*` to match any path segment:

```json theme={null}
{
  "from": "/blog/*",
  "to": "/articles/*",
  "status": 301
}
```

This redirects `/blog/my-post` to `/articles/my-post`.

### Regex Patterns

Use regex capture groups with `$1`, `$2`, etc.:

```json theme={null}
{
  "from": "/users/(.*)",
  "to": "/profile/$1",
  "status": 301
}
```

### Host-Specific Redirects

Apply redirects only to specific domains:

```json theme={null}
{
  "from": "/",
  "to": "/landing",
  "status": 200,
  "hosts": ["example.com", "www.example.com"]
}
```

### Domain Redirects

Redirect from one domain to another:

```json theme={null}
{
  "from": "old-domain.com",
  "to": "new-domain.com/*",
  "status": 301
}
```

### Excluding Assets

By default, wildcard redirects exclude asset files (files with extensions). To include assets:

```json theme={null}
{
  "from": "*",
  "to": "index.html",
  "status": 200,
  "assets": true
}
```

<Warning>
  Setting `assets: true` will apply the redirect to all files including CSS, JavaScript, and images. Use with caution.
</Warning>

***

## Common Use Cases

### Single Page Application

```json theme={null}
{
  "redirects": [
    {
      "from": "*",
      "to": "index.html",
      "status": 200
    }
  ]
}
```

### WWW to Non-WWW

```json theme={null}
{
  "redirects": [
    {
      "from": "www.example.com",
      "to": "example.com/*",
      "status": 301
    }
  ]
}
```

### Multiple Redirects with Priorities

```json theme={null}
{
  "redirects": [
    {
      "from": "/old-blog/*",
      "to": "/blog/*",
      "status": 301
    },
    {
      "from": "/docs/v1/*",
      "to": "/docs/latest/*",
      "status": 302
    },
    {
      "from": "*",
      "to": "index.html",
      "status": 200
    }
  ]
}
```

<Info>
  Redirects are processed in order. More specific rules should be placed before general wildcard rules.
</Info>
