Anush
1
Hi Experts,
Trying to figure out how this redirection can be configured.
https://devcentral.com/groups/Research/\* should get redirected to ""https://F5.com/devresearch/\*
“*” says whatever user type, it get populate same in redirection site
For example,
https://devcentral.com/groups/Research/F5experts get redirect to https://F5.com/devresearch/F5experts
this looks tricky as it has both static and variable path in URI.
Thanks
Anush
2
how about this? looks ok?
when HTTP_REQUEST {
log local0. "Incoming URI = [HTTP::uri]"
if { [string tolower [HTTP::host]] equals "devcentral.com" && [string tolower [HTTP::uri]] starts_with "/groups/Research/" } {
set uri [string map -nocase {"/groups/Research/" "/devresearch/"} [HTTP::uri]]
log local0. "New URI = $uri"
HTTP::redirect "https://f5.com[$uri]"
}
}
Vijay_E
3
This is a rough template. You may have to play around with the getfield command to achieve your requirements:
when HTTP_REQUEST {
if { ([HTTP::host] eq "devcentral.com") and ([HTTP::uri] starts_with "/groups/Research/") } {
HTTP::respond 301 Location "https://f5.com/devresearch[getfield [HTTP::uri] "/groups/Research" 2]"
}
}
Anush
4
minor change in above rule
when HTTP_REQUEST {
log local0. "Incoming URI = [HTTP::uri]"
if { [string tolower [HTTP::host]] equals "devcentral.com" && [string tolower [HTTP::uri]] starts_with "/groups/Research/" } {
set uri [string map -nocase {"/groups/Research" "/devresearch"} [HTTP::uri]]
log local0. "New URI = $uri"
HTTP::redirect "https://f5.com[$uri]"
}
}
Anush
5
again minor change
when HTTP_REQUEST {
log local0. "Incoming URI = [HTTP::uri]"
if { [string tolower [HTTP::host]] equals "devcentral.com" && [string tolower [HTTP::uri]] starts_with "/groups/Research/" } {
set uri [string map -nocase {"/groups/Research" "/devresearch"} [HTTP::uri]]
log local0. "New URI = $uri"
HTTP::redirect "https://f5.com[http::uri $uri]"
}
}
Hi Anush,
accuracy and performance wise the code below would be most effective…
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
HTTP::redirect "https://f5.com/devresearch/[string range [HTTP::uri] 17 end]"
}
… almost equals (but without -NOCASE support)…
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
HTTP::redirect "https://f5.com/devresearch/[findstr [HTTP::uri] "/groups/Research/" 17 end]"
}
… closely followed by a …
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
HTTP::redirect "https://f5.com/devresearch/[string range [HTTP::uri] [string length "/groups/Research/"] end]"
}
… almost equals (but without -NOCASE support) …
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
HTTP::redirect "https://f5.com/devresearch/[findstr [HTTP::uri] "/groups/Research/" [string length "/groups/Research/"] end]"
}
… closely followed by the less accurate (the [getfield] search patter may occour multiple times and without -NOCASE support) method …
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
HTTP::redirect "https://f5.com/devresearch/[getfield [HTTP::uri] "/groups/Research/" 2]"
}
… followed by the less accurate (the [string map] search patter may occour multiple times) and less performant method …
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
HTTP::redirect "https://f5.com[string map [list "/groups/Research/" "/devresearch/"] [HTTP::uri]]"
}
Update: Included the [findstr] command.
Cheers, Kai
I think the below code would work best for you -
if { ( [HTTP::host] eq “devcentral.com” ) and ( [HTTP::uri] starts_with “/groups/Research/” ) } then { HTTP::redirect “https://f5.com/devresearch/\[string range [HTTP::uri] 17 end]” }