Alokai
Optimize Delivery (CDN)

Redirects

The documentation only applies to instances deployed on Alokai@Edge.

Redirects only work with Custom Domains. If no custom domain is configured, redirect settings will have no effect.

Redirects allow you to forward incoming traffic from one URL to another. They are useful for maintaining SEO, handling domain changes, or ensuring consistent URL structures.

General behavior

  • Two redirect types are available: Predefined rules and Custom rules.
  • Both types can be active at the same time.
  • Custom rules take priority — if a request matches both a Custom and Predefined rule, the Custom rule applies.
  • Predefined rules apply only to hosts and paths not covered by Custom rules.
  • Changes may take a few minutes to propagate.

Predefined rules

Predefined rules apply simple, opinionated transformations to your domain. You can choose:

  1. WWW redirect – forwards example.com → www.example.com (requires example.com to be added as a custom domain first).
  2. Non-WWW redirect – forwards www.example.com → example.com (requires www.example.com to be added as a custom domain first).

You can also enable:

  • Remove trailing slash – automatically normalizes paths by removing / at the end of URLs.

Custom rules

Custom rules allow you to define exact URL-mapping logic by uploading a CSV file.

Rules

  • File format: host/old/path,newhost/new/path[,status_code] (no headers).
  • An optional third column specifies the HTTP status code: 301, 302, 307, or 308. If omitted, defaults to 308. It is recommended to always specify the status code explicitly — when omitted, the backend fills in the default value, so downloading the CSV later will include status codes for all rows regardless.
  • Up to 500 redirects are supported.
  • Each record can be up to 256 characters long.
  • Source format: Must start with either / (path only) or a domain name (e.g., example.com/path). Do not include http:// or https:// protocol — these will be rejected. The platform enforces HTTPS for all traffic, so specifying the protocol is unnecessary and not supported.
  • URL encoding: All % characters must be part of valid %HH URL encodings (where H is a hex digit 0-9, A-F). To include a literal % in your URL, encode it as %25. Invalid sequences like %key or %ZZ will be rejected with a validation error. %HH sequences in the file are decoded once before the rule is applied, in both the old and the new URL. Requests aren't decoded, so to match an encoded character in a request, write its % as %25: the old URL /a%2520b matches a request for /a%20b. In the old URL, you can also write \x25 instead (/a\x2520b). In the new URL, %20 becomes a raw space in the redirect, so write %2520 to redirect to %20.
  • Regular expressions (REGEX) are supported only in the path portion, not in domain names. Domains must be literal strings. Example: your-custom-domain.com/old-path/(product-[^/]+)/details,your-custom-domain.com/new-path/\1,301
  • A custom domain must be set up for redirects to work.
  • Special characters in paths should be escaped with a backslash (e.g., \. for a literal dot, \? for a literal question mark).
  • PCRE regex support – we support Perl Compatible Regular Expressions (PCRE) for advanced pattern matching. See PCRE2 documentation for details.
  • Uploading a new file replaces the entire redirect list.
  • If validation errors occur, the system displays the problematic rows.
  • Host redirection (changing domains) is supported but requires both source and target domains to be set within the rules.

How rules are matched

  • Each rule is matched against the host, path and query string of the request together (for example your-custom-domain.com/old-path?color=red), exactly as the request was received. The request is not URL-decoded before matching.
  • Rules are checked in the order they appear in the file. The first matching rule is applied, so put broad rules (such as a catch-all) last.
  • The new URL replaces only the part of the request that the old URL matched. Everything before and after the match is kept. For example, the rule /old,/new redirects /old-page?color=red to /new-page?color=red.
  • Rules that start with / can match anywhere in the path, not only at its start. For example, /en also matches /shop/en. To match from the start of the path, start the rule with the domain (for example your-custom-domain.com/en). Rules that start with a domain are always matched from the beginning.
  • The query string is part of the matched text. It is kept on the redirect as long as your pattern does not match it. If your pattern matches it (for example with a trailing (.*)), capture it and add it back in the new URL with a backreference.
  • Use \1 to \9 in the new URL to insert the text captured by the corresponding group in the old URL. A group that didn't match anything (for example an optional (?:/(.*))? for the request /en/login) inserts an empty string. Only the first occurrence of the pattern is replaced.
  • Matching is case-sensitive. To make a rule case-insensitive, add (?i) after the leading /, for example /(?i)en.
  • Lookaheads (?=...) and (?!...) are supported.
  • Don't use <, >, &, ", or ' in a rule. They're escaped when the rules are deployed, so they don't reach the matching engine as written:
    • An old URL that contains & never matches. To match a literal &, write \x26.
    • A new URL that contains & redirects to &amp;. To redirect to a literal &, write %26.
    • An old URL that contains <, such as a lookbehind (?<=...) or a named group (?<name>...), is invalid, and none of the rules in the file can be deployed. Rules aren't checked for this when you upload the file.

Tips

  • Always download the current file before uploading changes. Since new uploads overwrite the entire list, you must re-include existing redirects along with new ones.
  • Contact Customer Support if you need more than 500 redirects.

Steps

  1. Prepare a CSV file with your redirect rules.
  2. Upload the file in the Custom rules section.
  3. Enable Custom rules.
  4. (Optional) Download the current file to make modifications before future uploads.
  5. To remove custom rules, disable the feature and delete the file.

CSV Template

You can download a CSV template directly in Console.

Examples

Old URLNew URLStatus CodeRequestResultDescription
/old-path/(product-[^/]+)/details/new-path/\1/info(omitted)/old-path/product-X/details/new-path/product-X/inforetain product ID (defaults to 308)
/product-([^/]+)/color-([^/]+)/product/\1-with-color-\2301/product-X/color-Y/product/X-with-color-Ytwo capture groups, permanent redirect
your-custom.domain/old-path/(product-[^/]+)different.domain/new-path/\1302your-custom.domain/old-path/product-Xdifferent.domain/new-path/product-Xtemporary redirect with host change
/product/([^/]+\.html)/products/list/\1(omitted)/product/someproduct.html/products/list/someproduct.htmlsimple path redirect (defaults to 308)
/old-category/new-category301/old-category/shoes?color=red/new-category/shoes?color=redrest of the path and query string are kept

CSV structure with data taken from the above examples:

/old-path/(product-[^/]+)/details,/new-path/\1/info
/product-([^/]+)/color-([^/]+),/product/\1-with-color-\2,301
your-custom.domain/old-path/(product-[^/]+),different.domain/new-path/\1,302
/product/([^/]+\.html),/products/list/\1
/old-category,/new-category,301

Best practices

  • Use Predefined rules for domain normalization (www vs non-www, trailing slashes).
  • Use Custom rules for SEO migrations (product URL changes, category reorganizations).
  • Keep the list clean — remove obsolete rules to avoid confusion and unnecessary hops.
  • Test changes after enabling, especially when using REGEX, to prevent accidental loops or broad matches.

On this page