Forum Discussion

Phil_Agee_69879's avatar
Phil_Agee_69879
Icon for Nimbostratus rankNimbostratus
Dec 14, 2005

URL Rewriting

We are just getting started with iRule and are curious about the capability to rewrite URLs.

 

 

According to the following link (Joe Pruitt's log):

 

 

http://devcentral.f5.com/weblogs/Joe/archive/2005/07/27/1397.aspx

 

 

to rewrite a URL without changing the URL that the browser shows in the address bar, we can use something like:

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] equals "/foo" } {

 

HTTP::uri "/bar"

 

}

 

}

 

 

What we are looking for is to rewrite as follows:

 

 

http://www.domain.com/MyName

 

 

to

 

 

http://www.domain.com/CustomerHomePage.aspx?CustomerName=MyName

 

 

Would the rulle be something like:

 

 

when HTTP_REQUEST {

 

if( [HTTP]::uri /(/w+)/? {

 

 

HTTP::uri "/MyPage.aspx\?Param=$1"

 

 

}

 

}

 

 

Thanks Very Much,

 

Phil

 

2 Replies

  • Try this:

    
    when HTTP_REQUEST {
      if { [HTTP::uri] starts_with "/MyName" } {
        HTTP::uri "/CustomerHomePage.aspx?CustomerName=[HTTP::uri]"
      }
    }
  • Forgot to trim the leading /.... try this instead:

    
    when HTTP_REQUEST {
      if { [HTTP::uri] starts_with "/MyName" } {
        set uri [string trimleft [HTTP::uri] "/"]
        HTTP::uri "/CustomerHomePage.aspx?CustomerName=$uri"
      }
    }