docs
  1. SCAYLE Resource Center
  2. Developer Guide
  3. Basic Setup
  4. Redirects

Redirects

Overview

Storefront Core retrieves the redirects from the Storefront API which is synchronized with the SCAYLE Panel. When the redirects module is enabled, the Storefront Core will intercept requests and look up possible redirects through the Storefront API. If a matching redirect is found, Storefront Core will reply with a 30x HTTP response.
The target will be set in the Location header and the statusCode field (302, 303, 307, or 308) will be used as the exact status code.

Redirect status codes

CodeDescription
301Moved Permanently - This and all future requests should be directed to the given URI
302Found - Tells the client to look at (browse to) another URI
303See Other - Redirect to another page which does not represent the requested resource
307Temporary Redirect - Like 302, but the method and body must not change in the redirected request
308Permanent Redirect - Like 301, but the method and body must not change in the redirected request

Configuration

Enable redirects in the nuxt.config.ts, and add them to the whitelist.

redirects.enabled controls whether the redirects module is active and querying the Storefront API for redirects.
Disabled by default.
redirects.queryParamWhitelista list of query parameters that should be included in the Redirect lookup. All query parameters in the original URL that are not in the whitelist will be stripped before checking for redirects. The stripped query parameters (but not the whitelisted ones) will be re-attached to the redirect URL if one is found.
let config = {
    redirects: {
        enabled: true,
        queryParamWhitelist: [],
    }
}

Absolute and relative URLs

For every request, both the absolute and relative URLs are considered for redirects. If there are matching redirects for both the absolute and relative URLs, the redirect for the relative URL will be used.

Normalization

Before querying for possible redirects, the request URL is transformed into a normalized URL.

First, trailing slashes in the URL are removed. For example, https://example.com/products/ is turned into https://example.com/products.

Then query parameters that are not in the whitelist are removed. These query parameters will be re-attached to the redirect URL if one is found.

For example, if a redirect is defined for /men/jumpers to /men/sweaters, it will work even when additional tracking parameters are present.

Redirecting with a tracking parameter

If a query parameter should be included in the redirect lookup, add it to the queryParamWhitelist.

Redirecting with a whitelisted query parameter

Caching

To reduce latency and load on the Storefront API, the responses to redirect queries are cached by Storefront Core. The default cache TTL is 120 seconds, so the results should be active within a few minutes after making a change to the redirect configuration.

References