Forum Discussion
iRule Script request
Hello,
We have a redirect need as explained below. Please let me know if you have an iRule script that can satisfy it.
Redirect
https://bbb.aaa.com/level1/level2/level3.aspx?{dynamicallygeneratedID}
TO
http://www.aaa.org/level1/level2/level3.aspx?{dynamicallygeneratedID}
4 Replies
- Kevin_Stewart
Employee
Is there any specific condition that has to be met for this redirect to happen? Is it a specific URI?
if { [string tolower [HTTP::uri]] starts_with "/level1/level2/level3.aspx" } { ...Is it a specific host name?
if { [string tolower [HTTP::host]] equals "bbb.aaa.com" } { ...Or do you simply redirect all traffic from an HTTPS site to an HTTP site?
when HTTP_REQUEST { HTTP::redirect "http://[HTTP::host][HTTP::uri]" } - StephanManthey
Nacreous
In case you want to create an own ID (not sure if I got your question right) you can use this syntax:
set sessionid "TestSessionID=[format %09d [expr int(rand()*1e9)]].[format %09d [expr int(rand()*1e9)]]"The session ID could be used as an element of the http query or inside a cookie.
In an iRule you can use [HTTP::uri] which consists of [HTTP::path]?[HTTP::query].
- nitass
Employee
in case you want to redirect when both http host and path match.
e.g.
[root@ve11a:Active:Changes Pending] config tmsh list ltm virtual bar ltm virtual bar { destination 172.28.20.111:443 ip-protocol tcp mask 255.255.255.255 pool foo profiles { clientssl { context clientside } http { } tcp { } } rules { myrule } source 0.0.0.0/0 source-address-translation { type automap } vs-index 2 } [root@ve11a:Active:Changes Pending] config tmsh list ltm rule myrule ltm rule myrule { when HTTP_REQUEST { if { [HTTP::host] equals "bbb.aaa.com" and [HTTP::path] equals "/level1/level2/level3.aspx" } { HTTP::redirect "http://www.aaa.org[HTTP::uri]" } } } [root@ve11a:Active:Changes Pending] config curl -Ik https://bbb.aaa.com/level1/level2/level3.aspx?1234567890 HTTP/1.0 302 Found Location: http://www.aaa.org/level1/level2/level3.aspx?1234567890 Server: BigIP Connection: Keep-Alive Content-Length: 0 - StephanManthey
Nacreous
I´m wondering if Kevin´s and nitass´ advices already worked for you?
Perhaps you want to modify references in the HTTP payload received from the server as well?
In this case a so called stream profile will help you to modify the payload 'one the fly' and the content length will be recalculated accordingly.
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