Breadcrumbs

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 end with /(.*).

  • For internal Scroll site URLs: relative path

  • For external URLs: absolute path starting with //

  • 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

regex /my-path/(.*) /new-path/$1 temporary
/backbone-issue/(.*)/variant/(.*) /backbone-work-sync/$1/other-variont/$2 and so on

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.

Note that Scroll Sites uses Java-flavored regular expressions.

Example with single back reference

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:

literal /some-path /other-path permanent

Example with multiple back references

regex /source/(.*)/inserted-segment/(.*) /source/$1/other-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/basic/article

  • Scroll Sites redirects to: /source/latest/standard/article