Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

iRule Redirect for the same URL?

Hello All,

I am struggling to implement an iRule condition for the same URL where I can't use any redirects like 301, 302, 307, etc. because of infinite loop.

Here is the example.

Source URL: www.example.com/testing/irule

Destination URL: www.example.com/testing/irule/not/working/

so basically I want to add /not/working/ part before hitting the backend servers. I tried few techniques but no results yet.

Thanks as always, R

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

I don't think you need to use a redirect to do what you are trying to accomplish.

If it's a limited number of URLs, and the list is pretty static, why not just use a rewrite profile, which maps (in a reversible fashion) between an external and internal URL?

If the list isn't static, you could use a local traffic policy or iRule to rewrite the URLs in client requests and server responses.

0
Comments on this Answer
Comment made 26-Jul-2018 by Stephane Viau 122

when HTTP_REQUEST { switch [HTTP::path] { "/testing/irule" { HTTP::path [HTTP::path]/not/working } } }

But as rob said you might want to use a rewrite profile because rewriting URIs like this may cause other problems with your application if you do not also rewrite the HTML code sent back to the browser.

0
Comment made 26-Jul-2018 by Root44 405

Thank you, rob_carr and Stephane, for your inputs. The issue is, it is 126 lines of code where only this part has an issue, so I won't be able to add the rewrite profile which could be a help for few lines of code.

I tried something like this though and it didn't work:

if {[HTTP::uri] contains "/testing/irule/*"} { HTTP::uri "/not/working/" }

Do you see any issues in it?

0
Comment made 26-Jul-2018 by Stephane Viau 122

If you do :

HTTP::uri "/not/working/"

your URI will be "/not/working", not "/testing/irule/not/working".

If you wish to have /testing/irule/not/working, you need to do this :

HTTP::uri [HTTP::uri]/not/working

And ideally you should use HTTP::path instead of HTTP::uri because HTTP::uri contains the path AND the query string. So if your URL is something like http://somesite.com/testing/irule?user=username and you have some code that looks like "if HTTP::uri equals /testing/irule", you will never get a match because from the iRule point of view HTTP::uri would equal "/testing/irule?user=username".

0