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
- 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/" }
- dan_6764
Nimbostratus
Hi, - hoolio
Cirrostratus
Hi Dan,when 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 }
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