_redirects file in the repository’s root directory, Sevalla will parse the file’s contents and apply the custom redirect rules.
Redirect rule format and examples
Each redirect rule must be placed on its own line, with the original path followed by the new path or destination URL. Any line beginning with# will be treated as a comment and ignored. Paths are case-sensitive, and special characters must be URL-encoded.
For example:
Custom 404 page handling
You can create a custom 404 page for any path that doesn’t resolve to a static file; no redirect rules are required. Simply add a404.html file to your site, and it will automatically be shown whenever a path cannot be found.
You can also combine custom 404 pages with redirects by defining explicit rules for different languages or directory paths. For example:
Force redirects
In some cases, a redirect may not occur because an existing file matches the requested URL path. To override this behavior, you can force the redirect by adding an exclamation mark (!) to the status code.
For example:
/store/offers will always serve the content from /store/best-offers.html, even if a file such as /store/offers/index.html exists.
Splats
An asterisk (*) represents a splat, which matches anything that follows it in a path, for example:
/resources/guides/getting-startedto
/library/guides/getting-started.
Redirect rules always apply the first matching rule, therefore, more specific rules should appear before more general ones.
The following limitations apply to splats:
- **No mid-path wildcards: **You cannot place an asterisk in the middle of a path—for example,
/docs/*.htmlis not valid. Splats can only appear at the end of a segment. - **No exclusions within a splat rule: **You cannot exclude specific paths directly within a splat redirect. To handle exceptions, create a more specific rule above the splat rule, ensuring it is matched first.
Placeholders
You can use placeholders in both the origin and target paths to dynamically capture and reuse parts of a URL, for example:/store/electronics/headphoneswould redirect to /products/electronics/headphones.
A placeholder matches either:
- a single path segment between two slashes (
/), or - the final segment of a path, including any file extension but excluding the query string.
Query parameters
You can use query parameters to create more precise redirect rules.Matching a single query parameter
Example:/search?q=laptops to /results/laptops with a 301 redirect.
This rule matches only when the q parameter is present and no additional parameters are included. If the URL includes other parameters, such as &sort=asc, it will not match this rule.
Matching multiple query parameters
Add each parameter as its own key/value pair, separated by a space:/products?category=shoes&brand=nike to /browse/shoes/nike
Handling optional or multiple parameter combinations
When parameters may or may not be present, list redirects from most specific to most general so the correct rule is matched first. Examples:Single page applications (SPAs)
If your site is a single-page application, we strongly recommend adding a_redirects file to the root of your repository with the following rule:
index.html file with a 200 status, allowing your SPA’s router to handle the actual path logic.