Forum Discussion
cjunior
Sep 02, 2016Nacreous
Hi, I don't know if I clearly understood, so I would try another way:
1) Single string pattern for documents path (no regsub)
when HTTP_REQUEST {
if { [string tolower [getfield [HTTP::host] ":" 1]] equals "oldsharepoint.uk" } {
if { [string match -nocase "/*/*/documents/*" [HTTP::path]] } {
set uri [string range [HTTP::uri] [string first /documents [string tolower [HTTP::uri]]] end]
HTTP::respond 301 noserver Location "http://newsharepoint.uk/new${uri}"
unset uri
}
}
}
2) data group rewrite (I'd recommend for large list):
ltm data-group internal dg_redirect_shpt_paths {
records {
/a/1234/ {
data /new/
}
/b/1/ {
data /new2/
}
}
type string
}
when HTTP_REQUEST {
if { [string tolower [getfield [HTTP::host] ":" 1]] equals "oldsharepoint.uk" } {
set p [URI::path [string tolower [HTTP::uri]] 1 2]
set m [class match -value $p equals dg_redirect_shpt_paths]
if { $m ne "" } {
HTTP::respond 301 noserver Location "http://newsharepoint.uk[string map -nocase "$p $m" [HTTP::uri]]"
}
unset -nocomplain p m
}
}
3) rewrite with array list:
when CLIENT_ACCEPTED {
I don't like using statics variables, so here it is and not in RULE_INIT
array set redirect_shpt_paths {
/a/1234/ /new/
/b/1/ /new2/
}
}
when HTTP_REQUEST {
if { [string tolower [getfield [HTTP::host] ":" 1]] equals "oldsharepoint.uk" } {
set p [URI::path [string tolower [HTTP::uri]] 1 2]
foreach m [array names redirect_shpt_paths] {
if { $m eq $p } {
set uri [string map -nocase "$p $redirect_shpt_paths($m)" [HTTP::uri]]
HTTP::respond 301 noserver Location "http://newsharepoint.uk$uri"
}
}
unset -nocomplain p m uri
}
}
when CLIENT_CLOSED {
unset -nocomplain redirect_shpt_paths
}
If I'm wrong, I apologize,
Respectfully.