Forum Discussion
Irule - For redirection
How can I create an irule for redirection
https://www.test.com/promotion.jsp!/fanta-manager to https://www2.test.com/scommesse
This is what I have at the moment (Does not work)
when HTTP_REQUEST { if { (([string tolower [HTTP::host]] equals ";) and ([string tolower [HTTP::uri]] equals "/fanta-manager"))} { HTTP::redirect "; } }
Any help would be highly apprieciated.
Thkx
- CoolPolishGuy
Nimbostratus
Hello
I would use path instead of uri as you are only interested in a specific part of the uri. When you are not sure of what the objects are containing, you can always print them and check the /var/log/ltm and see how your iRule did behave. Be sure that the iRule is correctly applied to your VIP.
To print logs use the following
log local0. "my iRule is working" set uri [HTTP::uri] log local0. $uri `
You also use "contains" and to match the host or other elements. In general it looks legit what you did.
`when HTTP_REQUEST { if { (([string tolower [HTTP::host]] equals "www.test.com") and ([string tolower [HTTP::path]] contains "/fanta-manager"))} { HTTP::redirect "https://www2.test.com/scommesse" }
}
Take out the semi colons also.
Very important is to check the logs and you will very quickly see what the problem is.
Hope it helps
Cheers
You are trying to redirect an anchor tag (), but this isn't possible. The the anchor tag is never sent as part of the HTTP request by any browser, it is only interpreted locally within the browser.
Also see: https://devcentral.f5.com/questions/missing-anchor-from-redirect
- Andy_McGrath
Cumulonimbus
As already stated anchor tags are not passed to the web server so the F5 will not see them, the solution proposed is to use a STREAM profile and update the link in the HTML instead of doing a redirect.
Not tested this iRule but generally this should look for the text
and replace it with!/fanta-manager
but only if the request is to https://www.test.com/promotion.jsphttps://www2.test.com/scommesse
e.g. the link in the HTML might be
when HTTP_REQUEST { set streamFlg false STREAM::disable if { ([string tolower [HTTP::host]] eq "www.test.com") and ([string tolower [HTTP::uri]] eq "/promotion.jsp")} { set streamFlg true } } when HTTP_RESPONSE { if {$streamFlg} { STREAM::expression {@!/fanta-manager@https://www2.test.com/scommesse@} STREAM::enabled } }
Recent Discussions
Related Content
* 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