Forum Discussion
Redirect Loop
Hi all
New to iRules and I need help with a redirect here is what I would like to do (11.2.4 HF10)
User goes to existing site www.aaa.com
The user is redirected and presented with an informational page on www.bbb.com/communication; essentially saying that we are upgrading to a new version of software blah, blah
The user would hit continue and go back to www.aaa.com/default and not receive the temp informational page.
I have written a simple redirect but when the user hits continue it is re-executing the existing iRule (as it should) and just looping. Any suggestions or help would be greatly appreciated Thanks
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]"
Check if host header has a value
if {[HTTP::host] contains "www.aaa.com" } {
Log redirection
log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to MWC"
Redirect to the requested host and URI
HTTP::respond 301 Location "https:// on www.bbb.com/communication "
}
}
6 Replies
- Kevin_Stewart
Employee
This is what I might do:
iRule on site A VIP:
when HTTP_REQUEST { if { [URI::query [HTTP::uri] done] equals "1" } { HTTP::respond 302 Location "http://[HTTP::host]/default" "Set-Cookie" "SITEA=1;path=/" } elseif { not ( [HTTP::cookie exists SITEA] ) } { HTTP::respond 302 Location "http://www.bbb.com/communication" } }
Then in your site B link back to site A, add a "done=1" query string:
[a href="http://www.aaa.com/?done=1"]Click here to continue[/a]
On first request, the URI doesn't contain the done query string and the "SITEA" cookie doesn't exist, so redirect to site B. Clicking the link at site B issues a redirect back site A, which triggers an immediate redirect back to itself and setting the SITEA cookie. All subsequent requests should bypass both conditions.
- jaddie_85451
Nimbostratus
Kevin
Thank you for the fast reply
I apologize if this is a stupid question but the f5 does not own site bbb, so where would I attach
[a href="http://www.aaa.com/?done=1"]Click here to continue[/a]
Is there a good way to use the difference between aaa.com and aaa.com/defaukt
Thanks
- Kevin_Stewart
Employee
Replace the square brackets in the example with greater-than/less-than signs (the forum will block these tags).
You might, instead of the query string check, do something like this:
if { ( [HTTP::uri] equals "/default" ) and not ( [HTTP::cookie exists SITEA] ) }
- jaddie_85451
Nimbostratus
Kevin
Thanks again
In what example do I do this
if { ( [HTTP::uri] equals "/default" ) and not ( [HTTP::cookie exists SITEA] ) }
and do I still need to attach this
[a href="http://www.aaa.com/?done=1"]Click here to continue[/a]
Thanks
- Kevin_Stewart
Employee
First iRule modified:
when HTTP_REQUEST { if { ( [HTTP::uri] equals "/default" ) and not ( [HTTP::cookie exists SITEA] ) } { HTTP::respond 302 Location "http://[HTTP::host]/default" "Set-Cookie" "SITEA=1;path=/" } elseif { not ( [HTTP::cookie exists SITEA] ) } { HTTP::respond 302 Location "http://www.bbb.com/communication" } }
And no, you no longer need to modify the HTML link with a query string. So the above basically says:
- if the request to site A is for "/default" and the SITEA cookie doesn't exist, redirect to itself and set the SITEA cookie (presumably this request is coming from site B).
- Else if the request is not for "/default" and the SITEA cookie doesn't exist, redirect to site B.
- And by default, if the request is not for "/default" and the SITEA cookie exists, do nothing (pass the traffic through to site A).
- jaddie_85451
Nimbostratus
Kevin
Thank you so much for your assistance initial testing in our test environment indicates that this is working as desired. I truly appreciate your time and assistance.
Thank you once again.
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