F5 is upgrading its customer support chat feature on My.F5.com. Chat support will be unavailable from 6am-10am PST on 1/20/26. Refer to K000159584 for details.

Forum Discussion

DaleLeBlanc_140's avatar
DaleLeBlanc_140
Icon for Nimbostratus rankNimbostratus
Dec 26, 2013

iRule to Redirect to certain directory

I need to create an iRule that will redirect users to a certain directory:

 

User enters: http://sitename Redirect to: http://sitename/dev/central

 

I created this iRule:

 

when HTTP_REQUEST { if { [HTTP::host] equals "sitename"} { HTTP::redirect "sitename/dev/central" } }

 

When I point my browser to http://sitename, I get redirected to:

 

http://sitename/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/sitename/dev/central

 

3 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Try changing your redirect line to simply:

     

    HTTP::uri "/dev/central"

     

    And you may consider aging another clause after interrogating the hostname e.g.

     

    & [HTTP::uri] eq "/"

     

    Hope this helps

     

  • If I may add, unless you have multiple host names resolving to the same VIP, you could probably skip the host check and just evaluate an empty URI. Something like this:

    when HTTP_REQUEST {   
        if { [HTTP::uri] equals "/" } {       
            HTTP::redirect "http://[HTTP::host]/dev/central"           
        }       
    }    
    

    In the absence of a URI in the browser request (ie. http://sitemame), there is still a URI value, albeit invisible, of "/".

  • Kevin, your reply worked perfectly. Now, I just need to learn the syntax for iRules and HTTP_REQUESTS ;)

     

    Thanks for your input!