---
title: "Redirects"
url: https://docs.sentry.io/contributing/pages/redirects/
---

# Redirects

Redirects allow you to automatically redirect an incoming request path to a new destination path. When you move or rename a file, you should make sure to set up a redirect from the old path to the new path, so that the old URL still takes users to the right place.

## [Add a New Redirect](https://docs.sentry.io/contributing/pages/redirects.md#add-a-new-redirect)

There are two ways to add redirects in the Sentry docs:

* [Add a New Redirect in `middleware.ts` (Recommended)](https://docs.sentry.io/contributing/pages/redirects.md#add-a-new-redirect-in-middlewarets-recommended)
* [Add a New Redirect in `redirects.js`](https://docs.sentry.io/contributing/pages/redirects.md#example-redirect-in-redirectsjs)

Both files make the distinction between SDK docs (ie. end user docs) and developer docs.

Because Sentry has a limited number of `next.config.js` redirects, you should configure your redirects in `middleware.ts` whenever possible. You should only use `redirects.js` ie (`next.config.js`) if you need to use regular expressions and wildcard path segments in your redirects.

It's no longer recommended to use `vercel.json` for redirects due to its limitations (doesn't work on localhost, requires a static file ...)

### [Add a New Redirect in `middleware.ts` (Recommended)](https://docs.sentry.io/contributing/pages/redirects.md#add-a-new-redirect-in-middlewarets-recommended)

Set up all simple one-to-one redirects in `middleware.ts`.

To add a new redirect in [`middleware.ts`](https://github.com/getsentry/sentry-docs/blob/master/middleware.ts), add a new object to `REDIRECTS` with the following properties:

* `from`: The incoming request path.
* `to`: The new destination path you want to route to.

#### [Example Redirect in `middleware.ts`](https://docs.sentry.io/contributing/pages/redirects.md#example-redirect-in-middlewarets)

The example below redirects `https://docs.sentry.io/performance/` to `https://docs.sentry.io/product/performance/`:

`middleware.ts`

```typescript
const REDIRECTS: { from: PathWithTrailingSlash; to: string }[] = [

  {
    from: "/performance/",
    to: "/product/performance/",
  },

];
```

### [Add a New Redirect in `redirects.js`](https://docs.sentry.io/contributing/pages/redirects.md#add-a-new-redirect-in-redirectsjs)

Sentry has a limited number of Vercel redirects, so you should only configure redirects in `vercel.json` if your redirects need to use regular expressions. Otherwise, use [`middleware.ts`](https://docs.sentry.io/contributing/pages/redirects.md#add-a-new-redirect-in-middlewarets-recommended).

To add a new redirect in `redirects.js` (which is consumed by `next.config.js`'s [`redirects`](https://nextjs.org/docs/app/api-reference/next-config-js/redirects)), add a new object to the corresponding redirects with the following properties:

* `source`: The incoming request path pattern.
* `destination`: The new destination path you want to route to.

#### [Example Redirect in `redirects.js`](https://docs.sentry.io/contributing/pages/redirects.md#example-redirect-in-redirectsjs)

The example below redirects URLs like `https://docs.sentry.io/cli/:path*` to `https://docs.sentry.io/product/cli/:path*` with a [path pattern](https://nextjs.org/docs/app/api-reference/next-config-js/redirects#path-matching) or a [Regex](https://nextjs.org/docs/app/api-reference/next-config-js/redirects#regex-path-matching).

For example, `https://docs.sentry.io/cli/installation/` would be redirected to `https://docs.sentry.io/product/cli/installation/`.

`redirects.js`

```json
 "redirects": [
    {
      "source": "/cli/:path*",
      "destination": "/product/cli/:path*",
    },
 ]
```
