Forum Discussion
Sabir_Alvi
May 27, 2021Altocumulus
HTTP::redirect doesn't work for multiple conditions, URL redirect doesn't work using iRule
So I have 2 types of redirects to handle, based on 2 types of URI. When a URI in the HTTP_REQUEST matches the value in Datagroup 1, I want to redirect to a certain URL by retaining a certain part of ...
- May 27, 2021
Hi Sabir Alvi,
"redirected" variable must be defined before running code for line 8 and line 15.
If the first if does not match, iRule will give an error, because the "redirected" variable is not defined.
when HTTP_REQUEST { set redirected "false" set url_hosts [class match -value -- [HTTP::uri] starts_with DATAGROUP_1] if { $url_hosts ne "" } { set redirected "true" set LinkID [URI::query [HTTP::uri] id] HTTP::redirect "https://$url_hosts/links/$LinkID" } if { $redirected ne "true" } { set url_hosts [class match -value -- [HTTP::uri] starts_with DATAGROUP_2] if { $url_hosts ne "" } { set redirected "true" HTTP::redirect "https://$url_hosts" } } if { $redirected ne "true" } { HTTP::respond 404 content "<Some HTML Code for error page>" } }
May 27, 2021
Hi Sabir Alvi,
"redirected" variable must be defined before running code for line 8 and line 15.
If the first if does not match, iRule will give an error, because the "redirected" variable is not defined.
when HTTP_REQUEST {
set redirected "false"
set url_hosts [class match -value -- [HTTP::uri] starts_with DATAGROUP_1]
if { $url_hosts ne "" } {
set redirected "true"
set LinkID [URI::query [HTTP::uri] id]
HTTP::redirect "https://$url_hosts/links/$LinkID"
}
if { $redirected ne "true" } {
set url_hosts [class match -value -- [HTTP::uri] starts_with DATAGROUP_2]
if { $url_hosts ne "" } {
set redirected "true"
HTTP::redirect "https://$url_hosts"
}
}
if { $redirected ne "true" } {
HTTP::respond 404 content "<Some HTML Code for error page>"
}
}
- Sabir_AlviMay 27, 2021Altocumulus
Thanks a lot, this just worked the way I wanted to!
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