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

Michael_107360's avatar
Nov 13, 2013

Partial Redirect based on URI

I need advise on my iRule, This is for a Partial Redirect based on URI These are the requirments

 

  1. any URL with NO URI redirects to HTTPS www.website.com redirects to https://www.website.com
  2. any URI listed below redirect to HTTPS www.website.com//default.asp to https://www.website.com//default.asp
  3. if URI's are other than listed DO NOT redirect continue on Port 80 www.website.com/checkthisout.html no redirection

I believe I have fulfilled 2 and 3 however I am not sure how to include redirection to a URL with NO URI, while fulfilling all the other requirements. Please take a look at this. Thank you!

 

when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/default.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/default.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/default-client.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/american-express-gold-card.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/american-mastercard.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/american-world-elite-mastercard.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/american-world-mastercard.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/platinum-card-from-american-express.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/client-login/default.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/client-login" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/client-login/esignature.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/client-login/logout.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/client-login/message-center/retrieve.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/Quicken" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/Quicken/default.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } }

 

4 Replies

  • Sorry for the formating problems......

     

    when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/default.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } etc. etc. etc. } }

     

  • ok lets make it simple same rules apply

     

    when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/default.asp" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } elseif { [string tolower [HTTP::uri]] contains "/cash-cards-and-lending/cards/" } { HTTP::redirect https://[HTTP::host][HTTP::uri] } } etc. etc.

     

  • First thing, a URI will always exist. If the client enters nothing in the browser, then the URI will simply be "/".

    Second thing, your iRule can be super simplified with a data group, which not only makes the iRule shorter, but makes the list of redirected URIs easier to manage. Example:

    A string-based data group (ex. my_redirect_class)

    "/default.asp" := ""
    "/cash-cards-and-lending/cards/" := ""
    "/cash-cards-and-lending/cards/default.asp" := "" 
    "/default-client.asp" := "" 
    "/cash-cards-and-lending/cards/american-express-gold-card.asp" := ""
    "/cash-cards-and-lending/cards/american-mastercard.asp" := "" 
    "/cash-cards-and-lending/cards/american-world-elite-mastercard.asp" := "" 
    "/cash-cards-and-lending/cards/american-world-mastercard.asp" := "" 
    "/cash-cards-and-lending/cards/platinum-card-from-american-express.asp" := "" 
    "/client-login/default.asp" := "" 
    "/client-login" := "" 
    "/client-login/esignature.asp" := "" 
    "/client-login/logout.asp" := "" 
    "/client-login/message-center/retrieve.asp" := "" 
    "/Quicken" := "" 
    "/Quicken/default.asp" := ""
    

    And then the iRule:

    when HTTP_REQUEST {
        if { [HTTP::uri] equals "/" } {
            HTTP::redirect "https://[HTTP::host]/"
        } elseif { [class match [string tolower [HTTP::uri]] contains my_redirect_class] } {
            HTTP::redirect "https://[HTTP::host][HTTP::uri]"
        }
    }
    

    So if the URI equals "/" (nothing), redirect to the same host on HTTPS. If the URI contains any of the values in the data group, redirect to that URL on HTTPS. Otherwise do nothing.

    You could probably further simplify the data group by taking out some overriding values and use a "starts_with" condition in the iRule.

    "/default.asp" := ""
    "/cash-cards-and-lending/cards" := ""
    "/default-client.asp" := "" 
    "/client-login" := "" 
    "/Quicken" := "" 
    
    when HTTP_REQUEST {
        if { [HTTP::uri] equals "/" } {
            HTTP::redirect "https://[HTTP::host]/"
        } elseif { [class match [string tolower [HTTP::uri]] starts_with my_redirect_class] } {
            HTTP::redirect "https://[HTTP::host][HTTP::uri]"
        }
    }