Forum Discussion

John_LeMay_1062's avatar
John_LeMay_1062
Icon for Nimbostratus rankNimbostratus
Dec 19, 2005

Another uri rewrite question

I'm trying to write a simple iRule to check for a blank uri and replace it with "/string". It is possible there would be valid uri's passed (/string2 for example), so I only want to add "/string" if there is no current uri specified.

 

 

Here is what I have:

 

 

when HTTP_REQUEST {

 

set uri [HTTP::uri]

 

if { $uri eq "" }{ set uri "/string" }

 

if { $uri eq "/"}{ set uri "/string" }

 

HTTP::uri $uri

 

}

 

 

I've tried a few iterations, but everything I seem to try results in "/string" being appended to every client request (for example, a request for http://server/string2 becomes http://server/string2/string).

 

 

This rule is on a VS listening on port 443. There is a second server listening on port 80 with a similar rule meant to fix the uri and redirect the client to the 443 VS:

 

 

when HTTP_REQUEST {

 

set uri [HTTP::uri]

 

if { $uri eq "" }{ set uri "/string" }

 

if { $uri eq "/"}{ set uri "/string" }

 

HTTP::uri $uri

 

HTTP::redirect https://[HTTP::host][HTTP::uri]

 

}

 

 

I don't believe having both rules in place is causing the issue. The point of having both though is to catch and fix users who may access the site via http as well as those who may try to access the site directly via https.

2 Replies

  • I don't see any reason why your rule wouldn't work, but there is a bunch of extra code that you really don't need to be running.

     

     

    For your port 80 virtual, the HTTP::uri command is a no-op since you are using a redirect right after it. I'd change that rule to this:

     

     

    when HTTP_REQUEST {
      HTTP::redirect "https://[HTTP::host][HTTP::uri]"
    }

     

     

    And for your 443 virtual, you can combine your two equals statements into one with a string length command and only reset the URI if your condition is met.

     

     

    when HTTP_REQUEST {
      if { [string length [HTTP::uri]] <= 1 } {
        HTTP::uri "/string"
      }
    }

     

     

    Try this out and see if it works. If not, I'd suggest throwing in some logging to give you an idea as to what's going wrong.

     

     

    -Joe

     

     

  • In rereading my original post, it looks like I was a bit ahead of myself.

     

     

    I currently have only one rule set on the http VS, no rule on the https VS. Since we are not terminating SSL on the BigIP in this case, I won't be able to do much in any rule on the https VS anyhow.

     

     

    I'll have to handle whatever I need to on the http VS only.