Forum Discussion

sumeemonga_1547's avatar
sumeemonga_1547
Icon for Nimbostratus rankNimbostratus
Jun 30, 2016

i need help in writing the irule for host redirect , uri trim and port redirection

Requirement is like this , that if client calls

 

Request 1 If URL is https://samplesite.test.com:8443/abc/DEV should be redirected to http://othersamplesite.test.com:9080/abc

 

Request 2 If URL is https://samplesite.test.com:8443/abc/TST should be redirected to http://othersamplesite.test.com:9080/abc

 

please note that host is also changing along with the port from https to http

 

early help will be appreciated

 

3 Replies

  • hi , this is something is my approach but not sure whether it will work or not , all suggestions invited when HTTP_REQUEST { if {[HTTP::host] contains "samplesite.test.com"} { if {[HTTP::uri] ends_with "/DEV"} { HTTP::uri [string trimright [HTTP::uri] /DEV] HTTP::redirect "http://othersamplesite.test.com:9080[HTTP::uri]" } if {[HTTP::uri] ends_with "/TST"} { HTTP::uri [string trimright [HTTP::uri] /TST] HTTP::redirect "http://othersamplesite.test.com:9080[HTTP::uri]" } else { pool default } } }
  • Ideally, don't do it and consider re-configuring the servers to work with the same domain and URL. If this isn't possible, consider keeping either the domain or the URL the same between the F5 & the server. Changing everything, although feasible with iRule can be tough to scale and can consume too much resources on the F5.

     

    If you still want to implement as-is, consider these 2 links:

     

    Domain Masking

     

    URI Masking

     

  • it might sound unkind but did you do any research yourself between when when the requirement changed again and now? this is pretty common question and has been answered many times.

     

    first I would like to echo the remark by Odaah, all this tinkering is not helping the application in the long run. it would be better to just rebuild it like it should work then keep adding tricks in front of it, specially if you need other people to make it work.

     

    then towards an answer, if this is possible depends largely on how the system is setup. is this all behind one virtual server with different named hosts behind it in one pool?

     

    if so then the HTTP Host header and URI can be modified to send the traffic with a different setup to the backend server(s) and might be handled correctly. things can get more complex if the website contains links to the original website that don't work now. with mulitple pools it might still be possible, also select a different pool. if the target servers are not behind the F5 then it becomes really challenging and i would just go with the redirect.

     

    some example for the incoming traffic can be found here, they will require some tinkering for your situation though:

     

    https://devcentral.f5.com/questions/replace-part-of-irule-and-irule-applied-doesnt-work-47775

     

    https://devcentral.f5.com/questions/need-to-replace-part-of-uri-in-url-tried-many-irules-47743

     

    the proxypass irule might also be an option, it is framework to handle rewriting for incoming and outgoing requests.

     

    https://devcentral.f5.com/codeshare/proxypass-v10-v11