Forum Discussion
dan_6764
Nimbostratus
Jan 13, 2009HTTP redirect maintaining original URL
Hi,
I have a simple irule that works fine for what I need. A request comes in (say to www.mypage.co.uk), if the LB pool has no active nodes the client request is redirected to a " sorry" page.
when LB_FAILED {
HTTP::respond 302 Location "http://mypage.co.uk/sorry/"
}
What I would like is to perform the above but retaian the original URL " www.mypage.co.uk "
I have tried the below but it does not work.
when LB_FAILED {
HTTP::header replace Host "http://ctradetest.costcutter.com"
HTTP::respond 302 Location "http://csalestest.costcutter.com/sorry/"
}
Any ideas???
Thanks
Dan
3 Replies
- hoolio
Cirrostratus
If you want to redirect to the host or URI that the client made a request to, you'd need to save the host or URI in HTTP_REQUEST for every request and then reference it in LB_FAILED:when HTTP_REQUEST { Save the host header value set host [HTTP::host] Save the URI (not sure you want to do anything with the URI though) set uri [HTTP::uri] } when LB_FAILED { Send 302 redirect with the host header value from the request HTTP::respond 302 Location "http://$host/sorry/" }
Aaron - dan_6764
Nimbostratus
Hi,
thanks for this..
I'm not sure if it's going to do what i need though.
currently the redirect i have (the first part when LB_FAILED) redirects the user to the sorry page just fine.
What i was looking to do was redirect the user but without changing the address location in the client browser
so user comes in looking for www.mypage.com
but because there are no servers available (LB_FAILED) i redirect them to another url : www.sorry.com.
However, I want to retain their original url in the browser so if they just click refresh it comes back www.mypage.com and if there are any servers available they get the content they expected, if not back through the above cycle.
sorry about the convoluted description, but as you can guess irules and not my expertise! :-)
thanks
dan - hoolio
Cirrostratus
Hi Dan,
If you don't want the client to see the updated URI, you could create a sorry pool and use that pool in LB_FAILED.
Here is an untested example based on this post:
http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=2922629646when CLIENT_ACCEPTED { Initialise a variable to track whether the load balancing attempt has failed set retries 0 } when HTTP_REQUEST { Check if there has been a load balancing failure if { $retries > 0 } { Rewrite the URI if it hasn't already been rewritten if {not ([HTTP::path] contains "sorry")}{ Rewrite the URI for the sorry page HTTP::uri "/sorry/sorry.html" } } else { This isn't a retry, so save the request headers and data set request [HTTP::request] } } when LB_SELECTED { Check if there has been a load balancing failure if { $retries >= 1 } { Select a new pool member from the sorry pool LB::reselect pool sorry_pool } } when LB_FAILED { Track that the load balancing attempt failed incr retries Retry the HTTP request HTTP::retry $request } when HTTP_RESPONSE { There was a successful response, so we could reset retries to 0? set retries 0 }
If the sorry.html page references images or other content, you might need to add logic to HTTP_REQUEST to specify the sorry pool for any request which has "sorry" in the path.
If this doesn't work for you, can you add logging to the iRule and post the log output from /var/log/ltm?
Thanks,
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
