For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Bryce_Halkerst1's avatar
Bryce_Halkerst1
Icon for Nimbostratus rankNimbostratus
Oct 14, 2015

Domain Redirect iRule

All, Having issues with setting up irule to redirect any host equals with URL = / to redirect to the home page, then allowing anything coming over with /* to maintain the full path. Seems pretty straight forward, but I can't get the /* of the irule to take affect. Would appreciate any help with this. Probably something easy I am missing.

 

Thanks, Bryce

 

Existing iRule when HTTP_REQUEST { Domain 301 Redirect if { ([HTTP::host] equals "www.blah.com" ) or ([HTTP::host] equals "10.10.10.10") or ([HTTP::host] equals "blah.com") } { if { ([HTTP::uri] equals "/") } {

 

HTTP::respond 301 Location "http://www.blah.com/home/index.jsp" } }

 

Tried to implement the following with no success when HTTP_REQUEST { Domain 301 Redirect if { ([HTTP::host] equals "www.blah.com" ) or ([HTTP::host] equals "10.10.10.10") or ([HTTP::host] equals "blah.com") } { if { ([HTTP::uri] equals "/") } {

 

HTTP::respond 301 Location "http://www.blah.com/home/index.jsp" elseif { ([HTTP::uri] equals "/*") } { HTTP::respond 301 Location "http://www.blah.com[HTTP::uri} } }

 

2 Replies

  • The equals operator doesn't support a wildcard match. But nevertheless:

    } elseif { not ( [HTTP::uri] equals "/" ) } { 
        HTTP::respond 301 Location "http://www.blah.com[HTTP::uri]" 
    } 
    

    would create an infinite loop for any traffic that wasn't just "/". Important to observe of course that in the absence of a URI path in the browser, HTTP::uri will still return "/". So the first iRule didn't work?

    when HTTP_REQUEST {
        if { [HTTP::uri] equals "/" } {
            HTTP::redirect ...
        }
    }
    

    This explicitly states that if the URI path is nothing/empty, then redirect, and implies that anything else be allowed through. You may otherwise not be meeting the HTTP::host qualifications.

  • Hi, there are multiple syntax errors in the irule.

    try the following irules:

    when HTTP_REQUEST { 
        Domain 301 Redirect 
        if { ([HTTP::host] equals "www.blah.com" ) or ([HTTP::host] equals "10.10.10.10") or ([HTTP::host] equals "blah.com") } { 
            if { ([HTTP::uri] equals "/") } { 
                HTTP::respond 301 Location "http://www.blah.com/home/index.jsp"
            } elseif { !([HTTP::host] equals "www.blah.com") } { 
                HTTP::respond 301 Location "http://www.blah.com[HTTP::uri]
            } 
        }
    }
    

    or use a switch command:

    when HTTP_REQUEST { 
        switch -glob [string to lower [HTTP::host][HTTP::path]] {
            "www.blah.com/" -
            "blah.com/" -
            "10.10.10.10/" {HTTP::respond 301 Location "http://www.blah.com/home/index.jsp"}
            "blah.com/*" -
            "10.10.10.10/*" {HTTP::respond 301 Location "http://www.blah.com[HTTP::uri]"}
        }
    }