Rules Engine: Redirect Rules (beta)

If you are looking for simple redirects such as /this-url/ to /that-url/, please check out our guide on using redirects on Strattic.

This feature is in beta. If you would like to use it, please contact support@strattic.com.

RegEx Redirect Rules

Normally on a static website, more advanced redirect rules that use Regular Expressions (RegEx) typically wouldn’t work. Regular Expressions (RegEx) are used to dynamically match any number of URLs without creating a rule for each and even without knowing what those URLs might all be.However, Strattic now allows you to create and manage RegEx redirects from the Strattic Dashboard.

Strattic uses a slightly different approach for Regex Redirects formatting called Path-to-regex.

Path-to-regex is a library that is commonly used in web frameworks to match incoming requests to specific routes or endpoints. It works by converting a route string, which defines the structure of a URL, into a regular expression that can be used to match incoming requests.

For example, let’s say we have a web application with the following route:


This route will match any URL that starts with /users/ followed by a dynamic segment called :path. The :path segment is a placeholder that will match any value, and the actual value will be available as a parameter in the request object.

Here are some examples of Regex redirects and then the Path-to-regex format that is used on Strattic’s rules engine.

  • RegEx Format: ^/assets/img/pdf/(.*)/?$ 
  • Strattic Path-to-Regex Format: /assets/img/pdf/:path(.*) 

  • RegEx Format: ^/blog/\d{4}/\d{2}/\d{2}/(.*)  
  • Strattic Path-to-Regex Format: /blog/:year(\d{4})/:month(\d{2})/:day(\d{2})/:path(.*)  

  • RegEx Format: ^/files/(.*)/?$ 
  • Strattic Path-to-Regex Format: /files/:path(.*) 

  • RegEx Format:  ^/form/whitepaper/(.*)  
  • Strattic Path-to-Regex Format: /form/whitepaper/:path(.*)  

  • RegEx Format:  ^/resources/whitepapers/(.*)  
  • Strattic Path-to-Regex Format /resources/whitepapers/:path(.*) 

Create a new RegEx Redirect

  1. In your Strattic Dashboard, go to the Site Details page for a selected site and then to the Rules Engine > Redirect Rules
  1. Select “Live Site” or “Preview Site” depending on where you want to create the Redirect rule. Click “Add Rule” and you’ll see a popup which allows you to enter the following fields. Once you’ve filled in the fields, click “Add”.
  • Source URI: where you would define the path to be redirected. For example, /my-page/:path(.*) This will forward any URL that matches the pattern. 
    :path(.*) is a universal pattern meaning no matter what comes after /my-page/. It will always be redirected.
    Note: This field does not support query parameters and they should be added as a condition, see below.
  • Redirect Action: Define which HTTP redirect code (301, 302, 307, 308) is returned from the server. 
  • Redirect Target: Where site visitors will be redirected to.
    Example: /that=page/:path
    Use the variable to add the matched capture group to the Redirect Target URL
  • Forward Query Parameters: Determines whether or not URL query parameters will be passed along to the Redirect Target URL
  • Description: Optional description for your redirect
  • Conditions: Set the conditions determining whether or not the redirection should be triggered. Currently, the only condition is query parameters, but more flags like IP address or GeoLocation may be added in the future. The Rules Engine will read through the URL and only perform the redirect if the query parameters match the condition.

    Example: This redirection would only execute IF there is a parameter named campaign and that parameter is EQUAL TO Facebook.
  1. Once you’ve created your redirect rule, click “Deploy”. Deploying your changes can take several minutes. There is no need to go into your WordPress site and publish. 

Additional Actions:

  • Import/Export: Exporting will create a JSON file that can be imported to another site via the Import option
  • Export CSV: Export will create a CSV file that can be exported and then imported to another site via the Import option
  • Import CSV: To import an existing list of RegEx redirects, you can create a CSV file that has the following columns:
    • uri
    • target
    • action
    • forward query params
    • last
    • description
    • conditions
    • status
  • Sync to Preview / Sync to Live: You can copy your redirect rules to the Preview or Live site. Please note that this will overwrite any existing rules you have on that site.

Additional Actions per Redirect Rule:

  • Edit: You can edit a Redirect Rule and then click Deploy to deploy the changes to the Preview or Live site. While editing a rule, you can also change the status to active or disabled.
  • Move Up / Move to First / Move Down / Move to Last: The redirects will be handled in the order that they are listed.

Strattic is an end-to-end managed WordPress static publishing and hosting platform.
Try it free for 14 days, no credit card required.

Did this answer your question?