Skip to content

Rewrites

Refer this page to configure proxies for your domain requests. This feature is useful when you wish to keep request URL same but change the underlying handling endpoint.

Note: For demo purpose, we will be using www.nviztest.com domain as an example.
Here, we will be rewriting all requests to add n7- as a prefix before sending them to server, and for homepage we will add n7 as a prefix

Prerequisite

  1. You must have a domain configured on Nitrogen

Steps

  1. Click on Domains menu, then select Rewrites tab. Select appropriate domain from the domains dropdown. Step

  2. Click on Add New button at top right corner.

  3. You will be taken to a screen to provide rewrite details.
    Provide the required details:

    1. Comment: Provide short detail about the rewrite.
      Note: Please keep the comment meaningful and relevant.

    2. Rewrite Condition Type: We can configure rewrite based on multiple conditions.
      e.g. URL-pattern, HTTP-method, request-header, cookie, request-user's origin-country, request-IP, request-user's device-type, request's user-agent
      Select PATTERN for now.
      Note: You can add multiple conditions as per your need, by clicking +Add button.

    3. PATTERN VALUE: The URL-Pattern for which this rewrite will be applied.
      By default there will be few patterns available. Select All URLs for now.

    4. Origin: The origin endpoint where the requests are to be proxied.
      We will be selecting default www-origin for now.

    5. DOM Optimization: Ignore this switch for now. It Passes the request to DXA module that optimizes the HTML content to speed up page load.

    6. Source URL: It specifies the regex pattern for the request URL. It supports regex-groups as well.
      We will be putting ^/(\?.*)*$ here, to match homepage URL.
      If nothing is specified, the request is proxied as-it-is to the selected origin.

    7. Destination URL: It specifies the regex pattern for the final request URL that will be proxied to th selected origin. We can use the regex groups matched in source pattern here.
      We will be putting /n7$1 here. So that anything coming in the first regex-group in source pattern, will be prefixed with n7
      e.g.
      Simple homepage request will be proxied as /n7
      And, homepage request with any querystring like /?lang=en will get proxied as /n7?lang=en

    8. To configure proxy for requests for other pages we will need to add another rewrite rule. Click on +Add Rewrite Rule.
      Simply put Source URLvalue as /(.+) and Destination URL value as /n7-$1
      So now, any other request (other than homepage) will be prefixed with n7- and querystring will be appended as it is. e.g.
      /sales will be proxied as /n7-sales
      /sales?lang=en will be proxied as /n7-sales?lang=en
      Note: the first matched source pattern will be applied for proxying. Therefore, the ordering of the rules is of utmost importance. Step

    9. Click on Save button. The configured rule will be showed in Rewrites list.
      Step

Notes

  1. If no rewrite rule is present, by default every request will be proxied to the 1st origin as it is.

  2. The order of patterns is of utmost importance. The first matched rule gets applied. So, please manage the order accordingly.

  3. Any rule when added, gets placed at the bottom. Use reorder to place it as per need.

  4. These changes will only take effect when deployed. Saving them will only be saving them in draft. Please refer documentation about Deploy process for it.

  5. When configuring the rewrite rules, a maximum of three conditions are allowed to be added to each rule.

  6. Use Nitrogen debug header to identify which rule is getting applied to resource.