Forum Discussion
Redirect Problem
Hi, using a single and pool with multiple hosts, trying to do a redirect based on host name and uri match using the following.
when HTTP_REQUEST { log local0. "Request: [HTTP::host][HTTP::uri]" if {[HTTP::host] equals "website1.com"}{ if { ([HTTP::uri] contains "app/commission") or ([HTTP::uri] contains "api/tickets") or ([HTTP::uri] contains "api/manageclasses") or ([HTTP::uri] contains "app/trainer") or ([HTTP::uri] contains "app/target") } { HTTP::redirect "www.website2.com" }} }
If I select website1.com/app/commission matches but redirects to website1.com/app/commission/www.website2.com
Any help greatly appreciated
8 Replies
- THi
Nimbostratus
Try HTTP::redirect "http://www.website2.com"
- Samir_Jha_52506
Noctilucent
Avoid multiple uri in same condition. I believe
will be good option.matchclassUse below irule.
class redirectURIs { /abc/book /manage/pqr /checkin/xyz } when HTTP_REQUEST { if { [matchclass [HTTP::uri] contains redirectURIs] } { HTTP::redirect "http://www.website2.com" } }- THi
Nimbostratus
"matchlass" is depreciated command already in sw v10. You should use "class" commands instead. See: https://clouddocs.f5.com/api/irules/class.html - THi
Nimbostratus
Also the request uri could be converted to lower case to allow mixed upper and lower case letters in it. Use tolower command.: [string tolower [HTTP::uri]] - arripay_6298
Nimbostratus
Thanks THi, really appreciate you help, proper stuck on this. I have had amend slightly as the devs have changed the redirect to a page on the same host. I cant get access to the f5 at the moment but I think this what I have, no change of behaviour. Will add tolower when I can get on machine. Any further help greatly appreciated. when HTTP_REQUEST { log local0. "Request: [HTTP::host][HTTP::uri]" if {([HTTP::uri] contains "app/commission") or ([HTTP::uri] contains "api/tickets") or ([HTTP::uri] contains "api/manageclasses") or ([HTTP::uri] contains "app/trainer") or ([HTTP::uri] contains "app/target") } { HTTP::redirect "[HTTP::host]//restricted" } }
- Vijay_E
Cirrus
I would recommend using datagroup with "class match" instead of "matchclass" as this has been deprecated with the 10.x code version and later.
Try this:
when HTTP_REQUEST { log local0. "Request: [HTTP::host][HTTP::uri]" if {[HTTP::host] equals "website1.com"} { if { ([HTTP::uri] contains "app/commission") or ([HTTP::uri] contains "api/tickets") or ([HTTP::uri] contains "api/manageclasses") or ([HTTP::uri] contains "app/trainer") or ([HTTP::uri] contains "app/target") } { HTTP::respond 301 Location "http://www.website2.com/" } } } - arripay_6298
Nimbostratus
Hi guys, seem to have it working, I think I needed a more exact match on the uri, thanks to THi for your assistance, most certainly helped!
when HTTP_REQUEST { log local0. "Request: [HTTP::host][HTTP::uri]" if {([HTTP::uri] ends_with "/app/commission/commission-submission.html") or ([HTTP::uri] ends_with "/app/classmanagement/class-management.html") or ([HTTP::uri] ends_with "/app/classticket/ticket-search-template.html") or ([HTTP::uri] ends_with "/app/trainer/trainer.html") or ([HTTP::uri] ends_with "/app/target/target.html") or ([HTTP::uri] ends_with "/app/target/target-setup-country.html") or ([HTTP::uri] ends_with "/app/studio/studio.html") } { HTTP::redirect "https://[HTTP::host]/app/shared/restricted.html" } }- THi
Nimbostratus
you're welcome, arripay
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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