Docs update: Redirect paths with parentheses (#24062)

It took me quite a while to understand that in order to redirect from `/english(default)/:path` to `/en-us/:path`, I have to escape the parentheses in the source with double backslashes so I thought I'd suggest it as a small doc update.


## Documentation / Examples

- [x] Make sure the linting passes
This commit is contained in:
Julien Benchetrit 2021-04-17 22:40:35 +03:00 committed by GitHub
parent 6e22a440e2
commit 646a881183
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 1 deletions

View file

@ -154,6 +154,23 @@ module.exports = {
}
```
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
```js
module.exports = {
async redirects() {
return [
{
// this will match `/english(default)/something` being requested
source: '/english\\(default\\)/:slug',
destination: '/en-us/:slug',
permanent: false,
},
]
},
}
```
## Header, Cookie, and Query Matching
Note: this feature is still experimental and not covered by semver and is to be used at your own risk until it is made stable.

View file

@ -82,7 +82,7 @@ module.exports = {
### Regex Path Matching
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/post/:slug(\\d{1,})` will match `/post/123` but not `/post/abc`:
To match a regex path you can wrap the regex in parentheses after a parameter, for example `/post/:slug(\\d{1,})` will match `/post/123` but not `/post/abc`:
```js
module.exports = {
@ -98,6 +98,23 @@ module.exports = {
}
```
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
```js
module.exports = {
async redirects() {
return [
{
// this will match `/english(default)/something` being requested
source: '/english\\(default\\)/:slug',
destination: '/en-us/:slug',
permanent: false,
},
]
},
}
```
## Header, Cookie, and Query Matching
Note: this feature is still experimental and not covered by semver and is to be used at your own risk until it is made stable.

View file

@ -178,6 +178,23 @@ module.exports = {
}
```
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
```js
module.exports = {
async redirects() {
return [
{
// this will match `/english(default)/something` being requested
source: '/english\\(default\\)/:slug',
destination: '/en-us/:slug',
permanent: false,
},
]
},
}
```
## Header, Cookie, and Query Matching
Note: this feature is still experimental and not covered by semver and is to be used at your own risk until it is made stable.