Forum Discussion

Justin_Kalb_440's avatar
Justin_Kalb_440
Icon for Nimbostratus rankNimbostratus
Nov 08, 2010

Irule to change page extension

Sorry this is a total noob post and if i am reposting please bear with me.

 

 

I am completely new to rewriting and in a situation where i am not able to directly interface with the f5. I am working with the following code:

 

 

when HTTP_REQUEST { if { [HTTP::uri] contains ".php" } { HTTP::redirect [HTTP::host] [HTTP::uri [string map -nocase {".php" ".html"} [HTTP::uri]]] } 

 

The intent is to remap all resuests for http://someserver.com/somepage.php to http://someserver.com/somepage.html. Can anyone shed light on the simplest way of making this redirect?

 

Thanks

 

Justin

 

  • George_Watkins_'s avatar
    George_Watkins_
    Historic F5 Account
    Hi Justin,

     

     

    Man! For not having access to a BIG-IP, you were almost dead on. I modified it slightly and this is what I came up with:

     

     

    when HTTP_REQUEST { 
    if { [HTTP::uri] contains ".php" } {
    HTTP::redirect http://[HTTP::host][string map -nocase {".php" ".html"} [HTTP::uri]]
    }
    }

     

     

    You should download a copy of LTM VE (http://tinyurl.com/f5ltmve). It is free and runs on VMWare ESXi, Workstation, or Player. I use it extensively for testing iRule code and configurations involving LTM. Hope this helps,

     

     

    George
  • As George suggests, LTM VE would be a great way to test this.

    Do you want the user to see the change to the file type? If so, then a redirect would work fine. If you want the change to be transparent to the user, you could change the redirect to a rewrite:

    
    when HTTP_REQUEST { 
       if { [HTTP::path] ends_with ".php" } {
          HTTP::uri [string map -nocase {".php" ".html"} [HTTP::path]]
       }
    }
    

    Aaron