[
{
"from": "string", // (required): The path. Supports regexp syntax.
"to": "string", // (required): The destination path.
"status": "number", // (optional): The HTTP Status Code for redirect. Default is empty.
"assets": "boolean", // (optional): Whether to apply the redirect/rewrite to any static file that is not an html file. Default is false.
"hosts": "Array<string>" // (optional): When provided, the redirect rule will apply only when the host name matches.
}
]
If you omit the status property, or provide a status different than 3xx, Stormkit will not redirect the
request but will simply rewrite the path.
[
{
"from": "/my-path/*",
"to": "/my-new-path/$1"
}
]
In this case, all requests coming to /my-path will be served as if they were coming to /my-new-path.
You can also use redirects as a proxy. If your redirect is an absolute URL (starting with http),
the request will be proxied.
[
{
"from": "/my-path/*",
"to": "https://example.com/my-new-path/$1",
"status": 200
}
]
In this case, all requests coming to /my-path will be proxied to https://example.com/my-new-path/*.
[
{
"from": "stormkit.io",
"to": "www.stormkit.io",
"assets": true,
"status": 301
}
]
[
{
"from": "/*",
"to": "/index.html"
}
]
The above example will rewrite all requests to index.html. By setting assets false This is useful for single page applications.
[
{
"from": "/documentation/*/page/*",
"to": "/docs/$1/$2"
},
{
"from": "/documentation$",
"to": "/docs"
}
]
You can use regexp syntax for redirects. The example above creates two redirects.
/documentation/welcome/page/getting-started to /docs/welcome/getting-started./documentation to /docs.Note the $amp; sign at the end of the string. That sign simply tells to redirect only the path /documentation and not anything that contains /documentation.
[
{
"from": "/path",
"to": "/new-path",
"hosts": ["example-a.org"]
},
{
"from": "/path",
"to": "/different-path",
"hosts": ["example-b.org", "example-c.org"]
}
]
If you have multiple domains configured for your environment, you can specify for which host name the redirect rule should apply to.
The example above will rewrite the /path to /new-path for example-a.org and to /different-path for example-b.org and example-c.org.
Please note that if your application contains API routes, paths starting with /api will not be matched.
This is to allow /api routes to handle the redirect themselves.
If you do not have any API function, this rule does not apply.
You can configure the API routes through the Serverless configuration section.
By Default, when a page is not found, Stormkit will try to serve /404.html or /error.html if any of these files are found in your deployment. You can customize this behaviour as follows:
Custom Error File fieldThis setting will be applied to all of your deployments and take effect instantly. There is no need for a deployment.
Note If you have API routes configured, the custom error file will not be applied to the paths starting
with your API Path - which is /api by default.
Note Similarly, if you have serverless side logic, the custom error file will not be applied.
You can specify the same rules at an environment level. To do so:
These rules will be applied to all of your deployments and take effect instantly. There is no need for a deployment.