All Products
Search
Document Center

CDN:Parameter rewrite

Last Updated:Aug 14, 2023

Alibaba Cloud CDN allows you to rewrite URL parameters in requests before the requests are redirected to origin servers. You can ignore, add, delete, retain, and modify parameters.

Background information

  • A URL parameter is a name-value pair that follows a question mark (?) in a URL. If the URL contains multiple parameters, the parameters are separated by ampersands (&).

  • In some cases, a URL also contains a number sign (#) and characters that follow the number sign (#). The number sign (#) represents a position on a web page, and the character on the right is the identifier of the position. The number sign (#) leads a browser to a specific spot on a web page and does not affect the server. Therefore, the number sign can be ignored in back-to-origin requests. After the browser reads the character after the number sign #, the browser points to the specific spot. For example, in http://www.example.com/index.html#segment, #segment represents the segment spot of the index.html page. After the URL is opened in a browser, the browser points to the spot.改写参数图

Parameter priority

  • After you enable parameter rewrite, the query strings in origin URLs are rewritten. You can configure one or more rewrite rules. Rewrite rules take effect in the following order: Add > Delete > Reserve Only > Modify. If you configure multiple rewrite rules for the same parameter, only the rewrite rule that has the highest priority takes effect.

  • If you turn on Ignore Parameters, only the Add rewrite rule takes effect.

Usage notes

Parameter rewrite rules may conflict with the enhance break rule in Back-to-origin URL Rewrite and the Ignore Parameters feature. Make sure that the rules do not conflict with each other. The latest configuration takes effect.

Impact on cache keys

  • Parameter rewrite is performed on Alibaba Cloud CDN points of presence (POPs) for origin fetch. Internal Alibaba Cloud CDN links are not affected. The cache keys remain unchanged.

  • The Ignore Parameters feature is performed on Alibaba Cloud CDN POPs for edge processing. Internal Alibaba Cloud CDN links are affected. The cache keys are changed.

Procedure

  1. Log on to the Alibaba Cloud CDN console.
  2. In the left-side navigation pane, click Domain Names.
  3. On the Domain Names page, find the domain name that you want to manage and click Manage in the Actions column.
    Domain Names
  4. In the left-side navigation pane of the domain name, click Back-to-origin.

  5. Click the Parameter Rewrite tab.

  6. Turn on Feature Switch.

  7. In the Rewrite Parameters dialog box, configure the required parameters.

    You can configure different types of rewrite rules or specify multiple parameters in a rewrite rule based on your business requirements. For more information, see Configuration examples.

    回源参数改写
  8. Click OK to apply the rewrite rule.

    To modify a rewrite rule, find the rule on the Rewrite Parameters tab and click Modify in the Actions column.

    回源参数改写

Configuration examples

  • Example 1: Ignore all URL parameters

    1

    Parameter

    Example

    Ignore Parameters

    On

    Add

    None

    Delete

    None

    Reserve Only

    None

    Modify

    None

    Expected result

    Original request: http://example.com/index.html?code1=1&code2=2&code3=3

    Final request: http://example.com/index.html

  • Example 2: Retain specified parameters

    2

    Parameter

    Example

    Ignore Parameters

    On

    Add

    None

    Delete

    None

    Reserve Only

    code2

    Modify

    None

    Expected result

    Original request: http://example.com/index.html?code1=1&code2=2&code3=3

    Final request: http://example.com/index.html?code2=2

  • Example 3: Add, delete, and modify specific parameters

    3

    Parameter

    Example

    Ignore Parameters

    On

    Add

    code4=4

    Delete

    code2

    Reserve Only

    None

    Modify

    code3=0

    Expected result

    Original request: http://example.com/index.html?code1=1&code2=2&code3=3

    Final request: http://example.com/index.html?code4=4