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

dlogsdonmd's avatar
dlogsdonmd
Icon for Nimbostratus rankNimbostratus
Jan 09, 2017

iRule URL/URI redirect question

Hello, we're implementing Jira in our environment and we want to redirect users and agents to different URIs. I'm trying to implement a rule to do the below:

If user enters: http://support.domain.org/customers LB redirects to: https://support.domain.org/servicedesk/customer/portals

If user enters: http://support.domain.org/agents LB redirects to: https://support.domain.org/secure/Dashboard.jspa

My attempt at this is below, but I'm getting errors.

    when HTTP_REQUEST {

 if { [HTTP::host] equals "support.domain.org" and [HTTP::uri] starts with "/customer"} { 
         HTTP::redirect "https://support.domain.org/servicedesk/customer/portals" 
   } 
 }
 elseif { [HTTP::host] equals "support.domain.org" and [HTTP::uri] starts with "/agents"} { 
         HTTP::redirect "https://support.domain.org/secure/Dashboard.jspa" 
   } 
}
else {
      HTTP::respond 404 content "Unrecognized request to [HTTP::uri]" "Content-Type" "text/html" 
    }
}

Any assistance would be appreciated.

Thanks.

3 Replies

  • What errors are you seeing ? Maybe because of "starts_with" but you are not using the underscore.

    You can break it down like this or maybe use switch statements:

        when HTTP_REQUEST {
        if { [HTTP::host] eq "support.domain.org" } {
        if { [HTTP::uri] starts_with "/customers" } {
        HTTP::redirect "https://support.domain.org/servicedesk/customer/portals" 
        } elseif { [HTTP::uri] starts_with "/agents" } {
        HTTP::redirect "https://support.domain.org/secure/Dashboard.jspa"
        } else {
        HTTP::respond 404 content "Unrecognized request to [HTTP::uri]" "Content-Type" "text/html" 
        }
    }
    }
    
  • Hi, you can use irule shown below;

    when HTTP_REQUEST {

    if { ([HTTP::host] eq "support.domain.org") and ([HTTP::uri] starts_with "/customers") } { HTTP::redirect "https://support.domain.org/servicedesk/customer/portals" 
    } elseif { [HTTP::uri] starts_with "/agents" } {
    HTTP::redirect "https://support.domain.org/secure/Dashboard.jspa"
    } else {
    HTTP::respond 404 content "Unrecognized request to [HTTP::uri]" "Content-Type" "text/html" 
    }
    

    }

  • Hi dlogsdonmd,

    a nested

    [if]
    iRule structure shouldn't be that complex to setup. You may take a look to the syntax below to see how your initial requirement can be glued within a rather simple iRule...

    when HTTP_REQUEST {
    
         Parse the requested HOST-Name using lower case formating...
    
        set low_host [string tolower [HTTP::host]]
    
        if { $low_host equals "support.domain.org" } then { 
    
             Valid HOST-Name detected. Parse the requested PATH using lower case formating...
    
            set low_path [string tolower [HTTP::path]]
    
            if { $low_path starts_with "/customer" } then {
    
                 Redirect the request...
    
                HTTP::redirect "https://support.domain.org/servicedesk/customer/portals" 
    
            } elseif { $low_path starts with "/agents" } then {
    
                 Redirect the request...
    
                HTTP::redirect "https://support.domain.org/secure/Dashboard.jspa" 
    
            } else {
    
                 Allow the request?
    
            }
    
        } else {
    
             Invalid HOST-Name requested
    
            HTTP::respond 404 content "Unrecognized request to [HTTP::host][HTTP::uri]" "Content-Type" "text/html" 
    
        }
    
    }
    

    Note: The provided iRule uses a slightly more advanced syntax, by checking the requested Path/URI using lower case formating (more accurate).

    Cheers, Kai