Forum Discussion

spanudiez_29062's avatar
spanudiez_29062
Icon for Nimbostratus rankNimbostratus
Sep 16, 2016

Redirect HTTP::uri doesn't work properly.

Hi,

 

I have some issues with redirecting.

 

I have the following rules set up :

 

when HTTP_REQUEST { if { [HTTP::uri] starts_with "/test" } { HTTP::redirect https://usa.acme.com/something } if { [HTTP::uri] starts_with "/mail" } { HTTP::redirect https://usa.acme/webmail_exchange } if { ([HTTP::host] equals "acme.com") } { HTTP::redirect https://usa.acme.com } if { ([HTTP::host] equals "mail.acme.com") } { HTTP::redirect https://mail.acme.com/webmail_zimbra } }

 

My issue is with :

 

} if { [HTTP::uri] starts_with "/mail" } { HTTP::redirect https://usa.acme/webmail_exchange }

 

I don't know for what reason, the redirection doesn't work properly.

 

I think the issue might be with the fact that the full URL is the one from URL mail.acme.com.

 

The user needs to type http://mail.acme.com/mail in order to get to https://usa.acme/webmail_exchange, this one doesn't work, while all other rules work as intended.

 

Any help will be appreciated.

 

Thanks, Diez

 

1 Reply

  • Hi Diez,

    actually you've already answered your question yourself... 🙂

    if a request for

    http(s)://mail.acme.com/mail
    is received and the ruleset contains those two
    [if]
    conditions...

    if { [HTTP::uri] starts_with "/mail" } then {  
        HTTP::redirect https://usa.acme/webmail_exchange
    }   
    if { [HTTP::host] equals "mail.acme.com" } then {
        HTTP::redirect https://mail.acme.com/webmail_zimbra
    }
    

    ... then you would send two redirects for the very same request. This will result in an iRule exception (keep an eeye on your LTM logfile) and terminate the TCP connection before the redirect is send.

    To solve your problem you could either issue a

    return
    command after each single
    HTTP::redirect
    /
    HTTP::respond
    command to stop the processing of the current iRule...

    when HTTP_REQUEST {
        if { [HTTP::uri] starts_with "/test" } then {
            HTTP::redirect "https://usa.acme.com/something"
            return
        } 
        if { [HTTP::uri] starts_with "/mail" } then {
            HTTP::redirect "https://usa.acme/webmail_exchange"
            return
        }
        if { [HTTP::host] equals "acme.com" } then {
            HTTP::redirect "https://usa.acme.com"
            return
        }
        if { [HTTP::host] equals "mail.acme.com" } then {
            HTTP::redirect "https://mail.acme.com/webmail_zimbra"
            return
        } 
    }
    

    ... or by creating an collision free rule set...

    when HTTP_REQUEST {
        if { [HTTP::host] equals "acme.com" } then {
            if { [HTTP::uri] starts_with "/test" } then {
                HTTP::redirect "https://usa.acme.com/something"
            } elseif { [HTTP::uri] starts_with "/mail" } then {
                HTTP::redirect "https://usa.acme/webmail_exchange"
            } else {
                HTTP::redirect "https://usa.acme.com"
            }
        } elseif { [HTTP::host] equals "mail.acme.com" } then {
            if { [HTTP::uri] starts_with "/test" } then {
                HTTP::redirect "https://usa.acme.com/something"
            } elseif { [HTTP::uri] starts_with "/mail" } then {
                HTTP::redirect "https://usa.acme/webmail_exchange"
            } else {
                HTTP::redirect "https://mail.acme.com/webmail_zimbra"
            }   
        } 
    }
    

    Cheers, Kai