- Rule Name:
Dynamic Redirect of Brand Locations [301]
(http.request.uri.path matches "^/locations/.*-tires-.*.asp$")
- Type:
Dynamic
- Expression:
concat("https://", http.host, lower(regex_replace(http.request.uri.path, "^/locations/.*.-tires-(.*).asp$", "/locations/${1}/")))
- Status Code:
301
- Preserve Query String?:
false
This expression uses a Regular Expression to match incoming request URLs that follow a specific pattern.
The pattern ^/locations/.*-tires-.*.asp$
breaks down as follows:
^
asserts the start of the line./locations/
matches URLs that begin with/locations/
..*
is a wildcard that matches any character (except newline) 0 or more times, used here to signify any string before-tires-
.-tires-
specifically matches this sequence of characters, indicating a particular segment in the URL path..*
again, matches any sequence of characters after-tires-
and before.asp
..asp
matches URLs that end with.asp
.$
asserts the end of the line.
concat()
function is used to join several string segments into one URL.https://
specifies the protocol of the redirect URL.http.host
includes the original host name of the incoming request.lower()
function converts the entire resulting URL to lowercase.regex_replace()
function takes the original path, matches it against^/locations/.*-tires-(.*).asp$
, and replaces it with/locations/${1}/
where${1}
represents the captured group in the original RegExp (the part of the URL that comes after-tires-
and before.asp
).- This effectively changes the URL structure from
/locations/<something>-tires-<brandName>.asp
to/locations/<brandName>/
, making the URL cleaner and more SEO-friendly.
Dope, this worked like a charm, thanks!