Forum Discussion

Anderson__Eric_'s avatar
Anderson__Eric_
Icon for Nimbostratus rankNimbostratus
Jun 29, 2007

Trailing / in URI

We're new to the F5 devices and coming up to speed, painfully. One issue we're having is we have a public URL that is accessed by our users and customers.

 

 

The issue at hand is if anyone doesn't provide the traililng / on, for example, www.domain.com/purchase, they get rejected. However, if they type in www.domain.com/purchase/ everything works fine. The IP is being load-balanced. The individual IPs of the devices works just fine.

 

 

Have written the below iRule without much luck. The issue appears to be with the concat and the trailing / not getting appended to the URI. 1) Is there a setting within the device itself, we're using 6400 boxes or 2) can someone assist with the code below and provide insight? The issue appears to be with the line for concat. Thanks in advance!

 

 

when HTTP_REQUEST {

 

Get URI and convert to lowercase

 

set uri [string tolower [HTTP::uri]]

 

Log the lowercase URI

 

log local0. "lowercase uri: $uri"

 

Find out if there is a period in the URL stopping when it sees a ?

 

if { [findstr $uri "." 0 "?"] eq "." }{

 

do nothing -- not ending in a virutal directory, URI syntax is good.

 

log local0. "URI is not a directory"

 

}

 

elseif { not ($uri ends_with "/") }{

 

it's a virtual directory and the trailing / doesn't exist, let's add it.

 

log local0. "URI is a directory, concatenating / to \$uri: $uri"

 

set $uri [concat $uri/]

 

}

 

update the URI before sending the request to the pool

 

log local0. "updated \$uri: $uri"

 

HTTP::uri $uri

 

}

3 Replies

  • Not sure if concat is valid, but you could just redirect them after the initial logic and add the trailing slash like this:

    
    when HTTP_REQUEST {
     Get URI and convert to lowercase
    set uri [string tolower [HTTP::uri]]
     Log the lowercase URI
    log local0. "lowercase uri: $uri"
     Find out if there is a period in the URL stopping when it sees a ?
    if { [findstr $uri "." 0 "?"] eq "." }{
     do nothing -- not ending in a virutal directory, URI syntax is good.
    log local0. "URI is not a directory"
    }
    elseif { not ($uri ends_with "/") }{
     HTTP::redirect http://[HTTP::host][HTTP::uri]/ 
     }
    }

    (might need to double-check my brackets there)

    That way if they bookmark the page it should end up with the slash in it.

    Denny
  • That would work but we've got more than just a few directories to take care into account. Additionally, don't want to have to modify this code each time a developer makes a change. This way requires maintenance and have better things to be working on. Thanks for the idea.
  • The redirect is generic, it will work for any directory (URI). Why are you thinking you'd have to change it? You should be able to apply it globally.

     

     

    EDIT: for example, www.domain.com/purchase will be redirected to www.domain.com/purchase/ and www.domain.com/sales will be redirected to www.domain.com/sales/ with the same rule.

     

     

    Denny