Forum Discussion

Darren_Person_2's avatar
Darren_Person_2
Icon for Nimbostratus rankNimbostratus
Mar 07, 2007

Vanity Url - Re-write URL

Hi!

 

 

As many of you who do .NET development on IIS know, creating a system to have clean URLs is very complex. I was hoping that we could leverage the F5 to assist, but am stuck as to how to begin. Given that the .NET pipeline always wants a file extension and we don't want to wildcard map all file extensions to go through the ASP.NET work process - we thought we could use the F5 to help us.

 

 

In IIS, we would write an HTTPModule and assign the ASP.NET pipleline for the file extension of .html.

 

 

Here are our business rules:

 

1. If the F5 receives a URL that does not contain a file extension it should append .HTML to the URL.

 

2. If the URL ends with a '/' the '/' should be removed before appending .HTML.

 

3. If the URL points to the root of the site .HTML should not be appended.

 

 

Can someone please help with how we should begin?

 

Thanks!!

 

1 Reply

  • It should be fairly straightforward to implement that logic in an iRule. You can use the 'HTTP::uri' command in the HTTP_REQUEST event to get/set the URI. You can use string functions to parse/modify the URI.

    Here's a quick draft:

    
    when HTTP_REQUEST {
        if the web app is case-insensitive, save the URI in lowercase
       set uri [string tolower [HTTP::uri]]
        log the lowercase version of the URI before modifying it
       log local0. "lowercase uri: $uri"
        check for the three logical cases
       if { $uri=="/" }{
          log local0. "URI was /: \$uri: $uri"
           do nothing
       }
       elseif { $uri ends_with "/" }{
          log local0. "URI ended with /: \$uri: $uri"
           replace the trailing / with .html
          set $uri [concat [string trimright $uri "/"].html]
       }
       elseif { not ($uri ends_with ".html" }{
          log local0. "URI didn't end with .html: \$uri: $uri"
           append .html
          set $uri [concat $uri.html]
       }
       else {
           did we miss a case?
          log local0. "default: \$uri: $uri"
       }
       log local0. "updated \$uri: $uri"
        update the URI before sending the request to the pool
       HTTP::uri $uri
    }

    Note that I didn't test all cases/exact syntax, but hopefully this gets you started.

    The log statements are written to /var/log/ltm. They should help you trace what the rule is doing. You should comment them out or remove them before using the rule in production.

    Aaron