For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Dan44's avatar
Dan44
Icon for Altostratus rankAltostratus
Nov 22, 2019

URL Rewriting

Hello together

Does anyone have experience with URL rewriting wit help of an iRule or a rewrite profile?

For a migration i have to rewrite a url. We have two pools (old-web, new-web) containing IIS web servers.

The url like:

https://www.myweb.com/webapp/v40/typ?filter=typ%3D10 should be rewritet to https://app.myweb.com/v40/typ?filter=typ%3D10

The problem is that app.myweb.com does't expect webbapp in the path, therefore it must be sent without /webapp/ to the host.

 i first tried it with an irule, this does not work unfortunately

when HTTP_REQUEST {
if {[string tolower [HTTP::host]] starts_with "www.myweb.com" && [string tolower[HTTP::path]] eq "/webapp/"} {
    HTTP::header replace Host "app.myweb.com"
    HTTP::uri "/"
	pool new-web 80
 
  }
}

Then i tried it with an rewrite profile

 Does anyone have any idea what I'm doing wrong?

2 Replies

  • I have no experience with rewrite profiles, but I may be able to help with that iRule.

    Your condition only matches when the path equals /webapp/, but you want it to match when it starts_with.

    Then after that it would rewrite the entire url to "/", not just remove the /webapp/ portion of the path.

    Instead you should be able to almost 1:1 use this example from here https://devcentral.f5.com/s/articles/irules-101-14-tcl-string-commands-part-2

    when HTTP_REQUEST {
       set uri [HTTP::uri]
       if { $uri starts_with "/axess2" } {
          HTTP::uri [string range $uri 7 end]
          pool pool1
       }
    }

    Adjusted to your own example:

    when HTTP_REQUEST {
        set uri [HTTP::uri]
        if {[string tolower [HTTP::host]] eq "www.myweb.com" && [string tolower $uri] starts_with "/webapp/"} {
            HTTP::header replace Host "app.myweb.com"
            HTTP::uri [string range $uri 7 end]
        	pool new-web
          }
        }
  • hi

    thanks. your example helped us to solve the problem.