Skip to content

Commit 006d0b2

Browse files
update contributing redirects instructions (#9774)
* update contributing redirects instructions * Apply suggestions from code review Co-authored-by: Liza Mock <[email protected]> --------- Co-authored-by: Liza Mock <[email protected]>
1 parent 53cddc9 commit 006d0b2

File tree

1 file changed

+46
-20
lines changed

1 file changed

+46
-20
lines changed

docs/contributing/pages/redirects.mdx

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,57 @@ title: Redirects
33
noindex: true
44
---
55

6-
76
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.
87

98
## Add a New Redirect
109

11-
Redirects are configured in [`next.config.js`](https://github.com/getsentry/sentry-docs/blob/master/next.config.js) and are checked before the filesystem (including pages and `/public` files ). The `redirects` function returns an array holding redirect objects.
10+
There are two ways to add redirects in the Sentry docs:
11+
12+
- [Add a New Redirect in `middleware.ts` (Recommended)](#add-a-new-redirect-in-middlewarets-recommended)
13+
- [Add a New Redirect in `vercel.json`](#add-a-new-redirect-in-verceljson)
14+
15+
Because Sentry has a limited number of Vercel redirects, you should configure your redirects in `middleware.ts` whenever possible. You should only use `vercel.json` if you need to use regular expressions in your redirects.
16+
17+
### Add a New Redirect in `middleware.ts` (Recommended)
18+
19+
Set up all simple one-to-one redirects in `src/middleware.ts`.
20+
21+
To add a new redirect in [`src/middleware.ts`](https://github.com/getsentry/sentry-docs/blob/master/src/middleware.ts), add a new object to `REDIRECTS` with the following properties:
22+
23+
- `from`: The incoming request path.
24+
- `to`: The new destination path you want to route to.
25+
26+
#### Example Redirect in `middleware.ts`
1227

13-
To add a new redirect, add a new object in the redirects array with the following properties:
28+
The example below redirects `https://docs.sentry.io/performance/` to `https://docs.sentry.io/product/performance/`:
29+
30+
```typescript {filename:middleware.ts} {2-5}
31+
const REDIRECTS: {from: PathWithTrailingSlash; to: string}[] = [
32+
{
33+
from: '/performance/',
34+
to: '/product/performance/',
35+
},
36+
];
37+
```
38+
39+
### Add a New Redirect in `vercel.json`
40+
41+
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`](#add-a-new-redirect-in-middlewarets-recommended).
42+
43+
To add a new redirect in [`vercel.json`](https://github.com/getsentry/sentry-docs/blob/master/vercel.json#L34), add a new object in `redirects` with the following properties:
1444

1545
- `source`: The incoming request path pattern.
16-
- `destination`: The new destination path you want to route to instead.
17-
- `permanent`: Whether the redirect is permanent and should be cached forever (`true`) or is temporary (`false`).
18-
19-
### Example Redirect
20-
21-
The example below adds a redirect for the alerts page after its parent folder was renamed from `alerts-notifications` to `alerts`.
22-
23-
```javascript {filename:next.config.js}
24-
redirects() {
25-
return [
26-
{
27-
source: '/product/alerts-notifications/',
28-
destination: '/product/alerts/',
29-
permanent: true,
30-
},
31-
]
32-
}
46+
- `destination`: The new destination path you want to route to.
47+
48+
#### Example Redirect in `vercel.json`
49+
50+
The example below redirects URLs like `https://docs.sentry.io/cli/(.*)` to `https://docs.sentry.io/product/cli/$1` with a matching regex pattern. For example, `https://docs.sentry.io/cli/installation/` would be redirected to `https://docs.sentry.io/product/cli/installation/`.
51+
52+
```json {filename:vercel.json}
53+
"redirects": [
54+
{
55+
"source": "/cli/(.*)",
56+
"destination": "/product/cli/$1"
57+
},
58+
]
3359
```

0 commit comments

Comments
 (0)