

# Redirects and rewrites

**Welcome to the new AWS Amplify**  
Amplify now puts hosting, a Postgres database, and sign-in in one AWS account. Deploy from your terminal or from Git, check every change in a preview first, and roll back in one step if something breaks.  
Looking for Amplify Hosting? See the [Amplify Hosting User Guide](https://docs.aws.amazon.com/amplify/hosting/userguide/welcome.html).

A redirect sends the browser to a different URL. A rewrite serves the content of a different path, and the browser keeps the URL that it requested.

You can set up redirects and rewrites in the following places:
+  **Routes in `amplify.jsonc` ** – AWS Amplify applies these rules before your app handles the request. This page describes them.
+  **Your framework’s configuration** – For example, use `redirects()` in `next.config.js` for Next.js. For Astro, use `redirects` in the Astro configuration or a `_redirects` file. Amplify applies your framework’s redirects as part of the deployment.
+  **A domain redirect** – To redirect a whole domain to another domain, such as `example.com` to `www.example.com`, configure the domain itself. For more information about custom domains, see [Use a custom domain](custom-domains.md).

## Add routes to amplify.jsonc
<a name="redirects-routes"></a>

The following `amplify.jsonc` configuration example adds a `routes` object. Each key is a path pattern, and each value sets the destination in `to` and, for a redirect, the status code in `status`. Replace the paths in the example with your own paths:

```jsonc
{
  "name": "my-app",
  "routes": {
    "/old-page": { "status": 301, "to": "/new-page" },
    "/docs": { "status": 302, "to": "https://docs.example.com/" },
    "/user/:id": { "to": "/user.html" }
  }
}
```
+ Set `to`. It can’t be empty. It’s a path in your app or, for a redirect, a full URL.
+ For a redirect, set `status` to `301`, `302`, `307`, or `308`. For a rewrite, omit `status` or set it to `200`.
+ Amplify deploys your routes with each deployment. To apply a change, deploy again.

If Amplify can’t apply a route, the deployment fails, and its status reason names the route. For example, a route with a `status` but no `to` fails with the following status reason:

```
routes./gone: "to" is required; a status-only route is not supported
```

If you use a status code other than the ones listed, the deployment fails with a reason such as `routes./see: "status" 303 is not supported; use 200, 301, 302, 307, or 308`.

### Path patterns
<a name="redirects-patterns"></a>

A pattern matches the whole request path. In a pattern:
+  ` ` matches any characters, including `/`. For example, `/blog/` matches `/blog/2026/post`.
+  `:name`, where `name` is any identifier, matches exactly one path segment. For example, `/user/:id` matches `/user/42`, but not `/user/42/settings`.
+ Every other character matches itself.

Because a pattern matches the whole path, `/old-page` doesn’t match `/old-page/`, and `/blog/*` doesn’t match `/blog`. To cover both, add a route for each.

Amplify uses `to` as written. It doesn’t add the part of the path that `*` or `:name` matched. A redirect also doesn’t include the request’s query string in the destination URL. To build the destination from the requested path, use your framework’s redirects or middleware.

### Route order
<a name="redirects-order"></a>

Amplify checks your routes in the order that you write them. It uses the first route that matches. Your routes come before your framework’s own routes, so a route in `amplify.jsonc` takes precedence over a page with the same path. Keep patterns narrow, because a broad pattern such as `/*` also matches your JavaScript, CSS, and image files.

### Use different routes in an environment
<a name="redirects-env"></a>

To use different routes in one environment, add `routes` under that environment in `env`. They replace the top-level routes for that environment. Amplify doesn’t merge them with the top-level routes.

```jsonc
{
  "name": "my-app",
  "routes": {
    "/old-page": { "status": 301, "to": "/new-page" }
  },
  "env": {
    "preview": {
      "routes": {
        "/old-page": { "status": 302, "to": "/new-page" },
        "/debug": { "to": "/debug.html" }
      }
    }
  }
}
```

An environment with an empty `routes` object, `"routes": {}`, uses no routes at all.

## Examples
<a name="examples"></a>

The following examples show common route configurations.

### Example – Redirect a page that moved
<a name="redirects-example-move"></a>

The following route redirects a page that moved:

```jsonc
"routes": {
  "/about-us": { "status": 301, "to": "/about" }
}
```

### Example – Redirect everything in a section to one page
<a name="redirects-example-section"></a>

The following route redirects everything in a section to one page:

```jsonc
"routes": {
  "/blog/*": { "status": 301, "to": "/articles" }
}
```

### Example – Redirect to another site
<a name="redirects-example-external"></a>

The following route redirects to another site:

```jsonc
"routes": {
  "/status": { "status": 302, "to": "https://status.example.com/" }
}
```

### Example – Keep the request method on a redirect
<a name="redirects-example-method"></a>

With a `301` or `302` redirect, the browser can change a `POST` request to a `GET` request. To keep the method and body, use `308` for a permanent redirect or `307` for a temporary one.

```jsonc
"routes": {
  "/api/v1/orders": { "status": 308, "to": "/api/v2/orders" }
}
```

### Example – Serve a single-page app for its client-side routes
<a name="redirects-example-spa"></a>

A single-page app that routes in the browser, with React Router or Vue Router for example, needs every client-side route to serve `index.html`, so that a deep link such as `/settings` works when a visitor opens or reloads it. Set `spa_fallback` at the top level of `amplify.jsonc`:

```jsonc
"spa_fallback": "/index.html"
```

Amplify serves the fallback for a request that matches no built file and no rule in `routes`. A request for a missing file with an extension, such as `/assets/old.js`, still returns 404. For more information, see [`spa_fallback`](yml-specification-syntax.md#config-ref-spa-fallback).

Don’t use a `"/*"` rewrite instead. It also rewrites your JavaScript, CSS, and image files to `index.html`. A server-rendered app on Next.js, Nuxt, Astro, or SvelteKit doesn’t need a fallback, because the framework handles every route.

## Coming from Amplify Hosting
<a name="redirects-classic"></a>

Amplify has no console rule editor. Move each Amplify Hosting rule to `routes` in `amplify.jsonc`, to your framework, or to a domain redirect. For more information about mapping Amplify Hosting rules, see [Migrate from Amplify Hosting](migrate-from-amplify-hosting.md).