Forum Discussion
Oct 28, 2019
Hi Jules,
Can you try this?
I added else statement for "if { [HTTP::uri] == "/" }"
when HTTP_REQUEST {
# log local0. "Host: [HTTP::host] and URI: [HTTP::uri]"
if { [HTTP::uri] == "/" } {
# searches for a hostname match in datagroup and redirects to the hostname match value <the redirect path> if found
if { [class match [HTTP::host] equals chevron--internal--redirect] } {
HTTP::respond 302 Location "[class match -value [HTTP::host] equals chevron--internal--redirect]"
}
else {
# No match found log and redirect to error page
log local0.info "Redirect for '[HTTP::host][HTTP::uri]' was not found in data group 'chevron--internal--redirect'"
HTTP::redirect http://www.404errorpages.com
}
}
else {
# searches for a hostname+uri match in datagroup and redirects to the hostname+uri match value <the redirect path> if found
if { [class match [HTTP::host][HTTP::uri] equals chevron--internal--redirect] } {
# log local0. "matched host and uri"
HTTP::respond 302 Location "[class match -value [HTTP::host][HTTP::uri] equals chevron--internal--redirect]"
}
elseif { [class match [HTTP::host] equals chevron--internal--keepURI_redirect] } {
# searches for a hostname match in datagroup and redirects to the hostname match value <the redirect path> while keeping the uri if found
# example: mysite.com/help redirects to yoursite.com/help
# log local0.info "Redirect for '[HTTP::host][HTTP::uri]' was found in data group 'chevron--internal--keepURI_redirect'"
set myuri [HTTP::uri]
set myhost [class match -value [HTTP::host] equals chevron--internal--keepURI_redirect]
HTTP::respond 302 Location "$myhost$myuri"
}
else {
log local0.info "Redirect for '[HTTP::host][HTTP::path]' was not found in data group 'chevron--internal--redirect' or 'chevron--internal--keepURI_redirect'"
HTTP::redirect http://www.404errorpages.com
}
}
}