If the storage path of your origin resources changes, you can keep the user access URL path unchanged. You can rewrite the URL at an Edge Security Acceleration (ESA) node. This action modifies the path and query string (request parameters) in the URL for origin fetch requests. The rewritten URL is then used to request resources from your origin server.
Function introduction
URL rewrites do not affect ESA internal links or the cache key. ESA nodes use the rewritten URL only for origin fetch requests.
The following examples show common scenarios for URL rewrites:
Example 1: Rewrite only the path

Example 2: Rewrite both the path and the query string (request parameters)

Procedure
In the ESA console, select Websites. Then, in the Website column, click the target site.
In the navigation pane on the left, select .
On the Rewrite URL tab, click Create Rule and enter a Rule Name.
In the If requests match... section, define the conditions that a request must meet. For more information, see Components of a rule expression.
In the Rewrite URL section, set the rewrite values for the Path and Query String.
Rewrite object
Operation method
Description
Path
Keep
Keeps the path from the original request without modification.
Rewrite To...
Static
Replaces the original request path with a destination path. Only a fixed string is supported.
Dynamic
The destination path can be set to an expression to perform a dynamic rewrite operation.
Query String
Keep
Keeps the query string from the original request without modification.
Rewrite To...
Static
Replaces the original query string with a destination query string. Only a fixed string is supported.
Dynamic
The destination query string can be set to an expression to perform a dynamic rewrite operation.
Click OK.
Configuration examples
Examples for static operations
The path in the original URL is replaced with a new path for all user requests that match the rule.
Rewrite object: Path
Original request URL:
https://example.com/examplefile.pngNew path:
/image/example.pngRewritten request URL:
https://example.com/image/example.png
The query string in the original URL is replaced with a new query string for all user requests that match the rule.
Rewrite object: Query String
Original request URL:
https://example.com/examplefile.png?code=123New query string:
code=321Rewritten request URL:
https://example.com/examplefile.png?code=321
Examples for dynamic operations
A new path segment
/archiveis prepended to the URL path for all user requests that match the rule.Rewrite object: Path
Original request URL:
https://example.com/examplefile.pngNew path expression:
concat("/archive", http.request.uri.path)Rewritten request URL:
https://example.com/archive/examplefile.png
An extra leading slash
/is removed from the URL path for all user requests that match the rule.Rewrite object: Path
Original request URL:
https://example.com//examplefile.pngNew path expression:
wildcard_replace(http.request.uri,"/*","$1")Rewritten request URL:
https://example.com/examplefile.png
A new key-value pair
userid=123is prepended to the query string for all user requests that match the rule.Rewrite object: Query String
Original request URL:
https://example.com/examplefile.png?code=123New query string expression:
concat("userid=123&", http.request.uri.query)Rewritten request URL:
https://example.com/examplefile.png?userid=123&code=123
The first key-value pair is deleted from the query string for all user requests that match the rule.
Rewrite object: Query String
Original request URL:
https://example.com/examplefile.png?key1=value1&key2=value2&key3=value3New query string expression:
regex_replace(http.request.uri.query,"^[^&]+&(.*)$","$1")Rewritten request URL:
https://example.com/examplefile.png?key2=value2&key3=value3
The entire query string after the
?is deleted for all user requests that match the rule.Rewrite object: Query String
Original request URL:
https://example.com/examplefile.png?key1=value1&key2=value2&key3=value3New query string expression: Either of the following expressions can be used to delete the request parameters that follow the
?in the request URL.regex_replace(http.request.uri.query,".*","")wildcard_replace(http.request.uri.query,"*","")
Rewritten request URL:
https://example.com/examplefile.png?
References
Features related to rules have different priorities, re-entrancy capabilities, and levels of granularity. For more information, see Feature descriptions for rule-related functions.