Forum Discussion
jony23
Nimbostratus
Aug 30, 2018replace path and query with "unknown" path
Hi,
I need some help please,
We have the next url https://www.host.com/abc/def/ghi?query=value&query1=value1 and the query could change depending on the request.
We have to do a 301 redirect to a ne...
Lee_Sutcliffe
Nacreous
Aug 31, 2018After seeing the logs I can see that the keys as well as the values can be different, so this required a slightly different approach.
This time the iRule will read the query, break it apart into a list and loop through each query, appending the value of each query key to a new URI. Once complete it will add this new, dynamically built URI to the redirect.
I've tested it and it seems to do what's required. Please check and let me know how you get on
when HTTP_REQUEST {
split each query into a list using & as separator
set queryList [split [HTTP::query] "&"]
set newUri "/path/"
set i 0
if { [HTTP::host] equals "www.host.com"} {
if { [HTTP::uri] starts_with "/path/" } {
loop through each query and append value to $newUri
foreach param $queryList {
set query [split [lindex $queryList $i] "="]
set value [URI::query [HTTP::uri] [lindex $query 0]]
append newUri $value /
incr i
}
redirect to new URI after looping has finished
log local0. "new URI is $newUri - redirecting"
HTTP::respond 301 noserver Location "https://[HTTP::host]$newUri"
}
}
}
Lee
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects