Forum Discussion

Sorin_Rusnac_86's avatar
Sorin_Rusnac_86
Icon for Nimbostratus rankNimbostratus
Mar 12, 2008

iRule to overwrite Page Extension help!

Hi -

 

 

Hoping somebody can help me is there a sample or code i can use to overwrite file extenstions on pages is this possible?

 

 

For example what I want the iRULE to do is as follows:

 

 

Example: ‘http://ourdomain.com/JDE/TaskExplorer/somelink.JSP’ gets rewritten to ‘http://ourdomain.com/JDE/TaskExplorer/somelink.jsp’

 

 

 

So it will rewrite uppercase JSP to lowercase jsp.

 

 

Thanks
  • hi,

     

     

    you should be able to do something like this:

     

     

    when HTTP_REQUEST {

     

    set path_without_extension [getfield [HTTP::path] "." 1]

     

    set extension [string tolower [getfield [HTTP::path] "." 2]]

     

    log local0. "path_without extension is $path_without_extension"

     

    log local0. "extension now is $extension"

     

    set new_path "$path_without_extension.$extension"

     

    log local0. "new path is: $new_path"

     

    HTTP::path $new_path

     

    }

     

     

    i added debugging data in case i missed something. Debugging info should be avaiable in /var/log/ltm through the CLI or in system>log>local traffic through the GUI

     

     

    i may have done an error ^^
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    In addition to nmenant's example, here are a couple more options:

    Here is a version which looks for any two to four character extension in all caps and sets it to lower case:

    
    when HTTP_REQUEST {
        Get the path (/path/to/file.ext)
          Use URI::basename to get the filename and extension (file.ext).
          Use getfield to split on the period, getting only the extension (ext).
          Prepend a period back to make the string more specific.
       set file_extension .[getfield [URI::basename [HTTP::path]] . 2 ]
        Log the parsed file extension
       log local0. "Original file extension: $file_extension"
        For two to four letter capitalized extensions, update the path with the lower case extension.
       switch -glob $file_extension {
          .[A-Z][A-Z] -
          .[A-Z][A-Z][A-Z] -
          .[A-Z][A-Z][A-Z][A-Z] {
              Set extension to lowercase
             set file_extension_lowered [string tolower $file_extension]
              Update the path by replacing the original file extension with the lowered case version
             HTTP::path [string map "$file_extension $file_extension_lowered" [HTTP::path]]
              Log the updated path (this should be removed when you're done testing).
             log local0. "Updated path: [string map "$file_extension $file_extension_lowered" [HTTP::path]]"
          }
       }
    }

    If you only wanted to update .JSP or any other mixed case of .jsp to .jsp, you could simplify the rule:

    
    when HTTP_REQUEST {
       HTTP::path [string map -nocase {.jsp .jsp} [HTTP::path]]
    }

    The second of the two options would be more efficient.

    Aaron
  • Thanks guys for all the help, I really appreciate the quick replies your help is much appreciated.