rewrite_​url

Version: v2025-01-13Includes use: Yes

Behavior name: Modify Outgoing Request Path

Modifies the path of incoming requests to forward to the origin. This helps you offload URL-rewriting tasks to the edge to increase the origin server's performance, allows you to redirect links to different targets without changing markup, and hides your original directory structure.

Except for regular expression replacements, this behavior manipulates path expressions that start and end with a / character.

Note: This behavior's rewrite operations can't override any of the base_directory behavior's settings.

Default behavior

These samples reflect the behavior's default settings. You can use these as is in your configurations or make adjustments based on the behavior's available options.

data "akamai_property_rules_builder" "rewrite_url" {
  rules_v2025_02_18 {
    name     = "Modify Outgoing Request Path"
    comments = "Modifies the path of incoming requests to forward to the origin."
    behavior {
      rewrite_url {
        behavior          = "REPLACE"
        match             = ""
        target_path       = ""
        match_multiple    = false
        keep_query_string = true
      }
    }
  }
}
"behaviors": [
  {
    "name": "rewriteUrl",
    "options": {
      "behavior": "REPLACE",
      "match": "",
      "targetPath": "",
      "matchMultiple": false,
      "keepQueryString": true
    }
  }
]

Options

Option Description
behavior
The action to perform on the path. Value is one of:
  • REPLACE. Specifies the match and target_path. For example, a match of /path1/ and a target_path of /path1/path2/ changes /path1/page.html to /path1/path2/page.html.
  • REMOVE. Specifies the match. For example, a match of /path2/ changes /path1/path2/page.html to /path1/page.html.
  • REWRITE. Specifies the target_url. For example, you can direct traffic to /error/restricted.html.
  • PREPEND. Specifies the target_path_prepend. For example, if set to /prefix/path1/page.html changes to /prefix/path1/page.html.
  • REGEX_REPLACE. Specifies the match_regex and target_regex. For example, specifying logo\\.(png|gif|jpe?g) and brand\$1 changes logo.png to brand.png.
match
When behavior is REMOVE or REPLACE specifies the part of the incoming path you'd like to remove or modify.
match_regex
When behavior is set to REGEX_REPLACE specifies the Perl-compatible regular expression to replace with target_regex.
target_regex
When behavior is set to REGEX_REPLACEthis replaces whatever the match_regex field matches. Value range is $1-$9.
target_path
Replaces whatever the match field matches in the incoming request's path.
target_pathPrepend
Specifies a path to prepend to the incoming request's URL.
target_url
Specifies the full path to request from the origin.
match_multiple
When enabled, replaces all potential matches rather than only the first.
keep_query_string
When enabled, retains the original path's query parameters.