Stormkit LogoStormkit Logo WhiteStormkit

Redirects and Path Rewrites

Stormkit is able to handle the path rewrites and redirects on the load balancer level. In order to make use of this feature, create a stormkit.config.yml file at root level of your repository. This file will be parsed on each deployment, hence if you change this file previous deployments won't be affected. The syntax is as follows:app: - redirects: - from: <string> to: <string> ext: <string> status: <number> replace: <bool> assets: <bool> static: <bool> host: <string>


FromThe URL or path to be rewritten/redirected. It accepts a pattern string.

'*' matches any sequence of non-Separator characters
ToThe destination URL or path.
ExtA list of extensions to match. If provided, the from clause will be ignored and only cdn clause will be interpreted. This property expects a string of extensions, separated by a comma.
StatusThe redirect status. When 'From' is a relative path, it defaults to an empty value and when it's empty the path will be rewritten. When 'From' is a host name, it defaults to 302.
AssetsSpecifies if the assets should also be considered for this rewrite/redirect. If true, the assets won't be redirected. Any file that has not an .html extension and has not an empty mime type is considered as a static asset. This variable is used only when 'From' is a path and not an absolute URL.
CdnTells Stormkit that this request should be served from the CDN and not from the lambdas.
ReplaceSpeficies whether a string replace should be used while redirecting. When used with the `status` field, it will replace the `from` value with the `to` value.
HostRestricts the redirect rule to the specified host name.

Redirect non-www to www

app: - redirects: - from: to: status: 301 replace: true With replace: true we basically tell Stormkit to keep the URL.
For instance when it's true, will be redirected to, when it's false it will be redirected to

Path rewrites

app: - redirects: - from: /dist/* to: /my-other-dist/ replace: true You can rewrite paths by using the combination of* in the from setting andreplace being set totrue. This will tell Stormkit to replace anything that matches the 'from' statement with the 'to' statement, and keep the rest of the url.

Examples with the above settings:


SPA config

app: - redirects: - from: /* to: /index.html assets: false The above example will rewrite all requests to index.html. It applies only to CDN requests since cdn is set true. This is useful for single page applications.

CDN rewrites

app: - redirects: - from: /favicon.ico to: /favicon.ico cdn: true By default Stormkit provides an endpoint to serve files from the CDN. Sometimes however we need to serve files from the same domain. If you're using an isomorphic application, requests to the same domain will tell Stormkit to forward the request to the lambda function. Luckily, by setting the cdn config true we tell Stormkit to serve the files from the CDN.

If you don't want to match files one by one, you can also use the ext property. This will tell Stormkit to match only given extensions and load them from the CDN:app: - redirects: - ext: js,css,png # Separate list of extensions by comma cdn: true # Tell to load assets from CDN

Restricting hosts

app: - redirects: - from: /dist/* to: /my-other-dist/ replace: true host: When the host parameter is specified, Stormkit will check that the request host matches the parameter value. This is useful when you have a monorepo with multiple apps hosted and you want to make sure that the redirect applies only to given hosts.