You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
flag to disable encoding of regex matches in 'rewrites' and 'redirects'
primary use case:
* regex pattern matches a subset of the URL pathname
example (configs):
- source:
'/foo/:bar*'
- destination:
'/:bar'
- purpose:
* 'rewrites' rule would be used to silently ignore
the leading 'foo/' directory in path
* 'redirects' rule would be used to trigger a 301 redirect
to a new URL that removes
the leading 'foo/' directory in path
example (behavior):
- request URL path:
'/foo/a/b/c/d/e/f.txt'
- :bar interpolates to value (before encoding):
'a/b/c/d/e/f.txt'
- :bar interpolates to value (after default encoding):
encodeURIComponent('a/b/c/d/e/f.txt') === 'a%2Fb%2Fc%2Fd%2Fe%2Ff.txt'
* if the corresponding 'rewrites' or 'redirects' rule includes the flag:
{"raw": true}
then the raw value will be returned without any encoding
based on:
* upstream PR 85
vercel/serve-handler#85
references:
* pathToRegExp.compile(data, options)
https://github.com/pillarjs/path-to-regexp#compile-reverse-path-to-regexp
road blocks:
* pathToRegExp bug
pillarjs/path-to-regexp#260pillarjs/path-to-regexp#261
status:
- the desired behavior will remain broken until this PR is merged
- 'source' patterns that match one or more '/' characters
cause the library to throw an Error for a failed assertion
@@ -139,6 +139,16 @@ Now, if a visitor accesses `/projects/123/edit`, it will respond with the file `
139
139
140
140
**NOTE:** The paths can contain globs (matched using [minimatch](https://github.com/isaacs/minimatch)) or regular expressions (match using [path-to-regexp](https://github.com/pillarjs/path-to-regexp)).
141
141
142
+
By default, values matched by a regular expression are encoded by `encodeURIComponent` before being included in the rewritten URL. This encoding can be disabled with the flag:
In order to redirect visits to a certain path to a different one (or even an external URL), you can use this option:
@@ -167,7 +177,7 @@ Just like with [rewrites](#rewrites-array), you can also use routing segments:
167
177
168
178
In the example above, `/old-docs/12` would be forwarded to `/new-docs/12` with status code [301](https://en.wikipedia.org/wiki/HTTP_301). In addition `/old` would be forwarded to `/new` with status code [302](https://en.wikipedia.org/wiki/HTTP_302).
169
179
170
-
**NOTE:** The paths can contain globs (matched using [minimatch](https://github.com/isaacs/minimatch)) or regular expressions (match using [path-to-regexp](https://github.com/pillarjs/path-to-regexp)).
180
+
**NOTE:** The paths can contain globs (matched using [minimatch](https://github.com/isaacs/minimatch)) or regular expressions (match using [path-to-regexp](https://github.com/pillarjs/path-to-regexp)). Just like with [rewrites](#rewrites-array), you can also disable the encoding of regular expression matches by adding `{raw: true}`.
171
181
172
182
By default, the querystring and hash are not preserved by the redirect. The following boolean attributes enable this behavior:
0 commit comments