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.

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

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.

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

To add a new redirect in src/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.

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

middleware.ts
Copied
const REDIRECTS: { from: PathWithTrailingSlash; to: string }[] = [
  {
    from: "/performance/",
    to: "/product/performance/",
  },
];

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.

To add a new redirect in redirects.js (which is consumed by next.config.js's 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.

The example below redirects URLs like https://docs.sentry.io/cli/:path* to https://docs.sentry.io/product/cli/:path* with a path pattern or a Regex.

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

redirects.js
Copied
 "redirects": [
    {
      "source": "/cli/:path*",
      "destination": "/product/cli/:path*",
    },
 ]
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").