Skip to main content
Skip table of contents

Advanced (RegEx) Redirects

Advanced redirects can redirect whole groups of pages to help you handle migration scenarios or create the impression of a certain structure.

Scroll Sites lets you create advanced redirects using regular expression (RegEx). RegEx helps you dynamically match any number of URLs without having to create a rule per URL or even knowing what those URLs might all be.

Create and Edit an Advanced Redirect

You can create and manage advanced redirects for your Scroll site from your site’s settings:

  1. From the My Sites screen, click the card that has your site’s name.

  2. From the left sidebar, click Site Settings > Redirects.

  3. Click Advanced redirects. The Advanced redirects dialog opens.

  4. In the Configuration field, enter your redirect(s) in the permitted format (see next section for more details).

  5. Click Save. You are taken back to the site settings where you will now see a list of created redirects.

  6. Click Publish changes or Save changes in the top right of the settings.

Your change will now automatically trigger a new site update (for sites set to live updates) or be applied with your next site update (for sites set to manual updates).

After the redirect is applied, whenever your selected source pages are opened, they will always redirect to the target URL you have specified in your redirect rule.

Permitted Values

When using the configuration field in the advanced redirect dialog, you will need to make sure to follow a set format and stick to the permitted values.

To setup a new redirect you should always use the following format:

<mode> <source> <target> <type>

Choose from the permitted values in the table below.

Required format:

Mode

Source

Target

Type

Permitted values:

  • regex

  • literal

Relative path of the Scroll site URL with regular expression capture groups.

For example: Can contain path segment capture groups ([^/]+) and end with /(.+).

  • For internal Scroll site URLs: relative path

  • For external URLs: absolute path starting with //

Redirect targets can make use of back references and chaining.

  • permanent

  • temporary

Some helpful tips for creating redirects:

  • For protocol-relative links (links that should remain https), you can write //www.example.com as a short-form of https://www.example.com.

  • If multiple regex rules match a path the first match will fire. Put your most specific rules first.

  • Scroll Sites URLs that are set as a redirect target can contain query parameters, such as in-app help query ?inAppHelp=true. The last regex group of a redirect rule also matches query parameters. Use a back reference in the target like in the example below to make sure query parameters are not lost.

Example of allowed redirects

CODE
regex /my-path/(.+) /new-path/$1 temporary

Disallowed Redirects

To prevent your users entering endless loops of redirects, we have placed the following limitations when creating redirects:

  • source and target value can’t be the same path

Disallowed paths

Redirecting from the site preview, root page or the search of your Scroll site is not possible. They correspond to the following disallowed paths:

  • /_search*

  • /preview*

  • /

Regular Expressions and Back References

Scroll Sites redirects use regular expressions (RegEx) to help you dynamically define a group of URLs and efficiently match these to other URLs.

For example, /content-source/(.+) will match on all paths starting with /content-source/. It has one group (.+) which will match any character, appearing at least one time.

The value that the group matches on can be reused in the target via back references. Back references start with a $ followed by the index of the group they reference. For example, $1 to reference the value of the first group. $0 is a special case that references the whole match, so the full path of the request.

There are two main types of capture groups:

  • /([^/]+)/ for matching a single path segment.

  • /(.+) for matching everything after the final slash (required at the end of a rule).

Note that Scroll Sites uses Java-flavored regular expressions.

Example with single back reference

CODE
regex /some-path/(.+) /other-path/$1 permanent

The rule will match on any path starting with /some-path/. It has one group (.+) which will match on any character, appearing at least one times. This results in the following behavior.

  • Users navigates to: /some-path/article?inAppHelp=true

  • Scroll Sites redirects to: /other-path/article?inAppHelp=true

Note that this will only redirect users visiting paths with at least one path segment after /some-path. If you also want to redirect users going directly to /some-path, consider adding an additional literal redirect:

CODE
literal /some-path /other-path permanent

Example with multiple back references

CODE
regex /source/([^/]+)/(.+) /source/$1/inserted-path-segment/$2 permanent

The rule will match on any path starting with /source/. The first group will match on a group of characters that does not contain a /. The second group will match on any character, appearing at least one times. This results in the following behavior:

  • Users navigates to: /source/latest/article

  • Scroll Sites redirects to: /source/latest/inserted-path-segment/article

Chaining Redirects

You can combine multiple redirects into a chain. When a redirect is applied to a path and the resulting target is not available, Scroll Sites will attempt to redirect the target yet again until it finds a resource that is available. This is useful when the page you want to redirect to might be available under one of several paths, as might be the case when using variants.

For instance, consider the following rules:

CODE
regex /os/(.+) /os/windows/$1 permanent
regex /os/windows/(.+) /os/macos/$1 permanent
regex /os/macos/(.+) /os/linux/$1 permanent

Assuming, that the article the-linux-kernel is only available under the /os/linux/ path, if a user visits /os/the-linux-kernel the following chain of redirects will be executed:

  • /os/the-linux-kernel/os/windows/the-linux-kernel

  • /os/windows/the-linux-kernel/os/macos/the-linux-kernel

  • /os/macos/the-linux-kernel/os/linux/the-linux-kernel

If a redirect chain exceeds 10 steps, no resource is found, or if for a target Scroll Site can’t find another redirect, it will respond with a 404.

Advanced Redirects Limitations

In order to keep redirects fast and stable we have set the following limits in place:

  • A redirect target can contain 5 back references at most. If a rule has more than 5 back references it will be ignored.

  • If you use a back reference with an index that does not exist, the rule will be ignored.

  • Redirect chains with more than 10 steps will result in a 404.

  • If a redirect rule produces an URL longer than 2048 characters, it will be discarded and Scroll Sites will respond with a 404.

Escaping period/dots in the redirect

Dots in the source URL of your redirect can be escaped with a \. Add the character right before the period, like this:

/content-source/v1\.0/(.+) /documentation/current/$1 permanent

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.