Forum Discussion

Ashish_Gupta_In's avatar
Ashish_Gupta_In
Icon for Nimbostratus rankNimbostratus
Sep 29, 2016

IRules to pass through request

Hi All,

 

I am using below rewrite rule with pass through in Apache webserver which is working fine. Now my requirement is not to use Apache webserver and route the traffic directly from F5 to application server and to achieve this i am trying to apply below rewrite rule pattern in F5(irules). Could you please help me for the same.

 

RewriteRule ^/([^/]+)/(.*)$ /content/obi/$1/en/$2.html [PT,L,QSA]

 

2 Replies

  • If you can provide the rewrite logic required, I think someone in devcentral may be able to assist you.

     

  • Hi Ashish,

    you may try the iRule below as a startingpoint to replace your existing mod_rewrite functionality.

    The iRule will rewrite a client side request of...

    http(s)://www.domain.tld/path1/path2?query=1

    ... to a server side request of ...

    http(s)://www.domain.tld/content/obi/path1/en/path2.html?query=1

    ... or ...

    http(s)://www.domain.tld/path1/path2/path3

    ... to ...

    http(s)://www.domain.tld/content/obi/path1/en/path2/path3.html

    iRule:

    when HTTP_REQUEST { 
    
         Replacement for QSA option
    
        if { [HTTP::query] ne "" } then {
            set input_query "?[HTTP::query]"
        } else {
            set input_query ""
        }
    
         Replacement for RewriteRule
    
        set root_folder [substr [HTTP::path] 1 "/"]
        set remaining_path [string range [HTTP::path] [expr { [string length $root_folder]+2 }] end]
        HTTP::uri "/content/obi/${root_folder}/en/${remaining_path}.html${input_query}"
    
    }
    

    Note: You may also post any previous RewriteRules to see if certain URIs requiring exemptions for the given rewrite.

    Note: To assist you with the

    PT
    option, its required to know your existing aliases (if configured).

    Note: The

    L
    option is already implied within
    PT
    and doesn't require special attention within iRules.

    Cheers, Kai