Forum Discussion

wick54's avatar
wick54
Icon for Nimbostratus rankNimbostratus
Nov 19, 2019

URI Redirect using an iRule

Hi Guys,

 

We have a requirement for an application that we are migrating to F5 to have " /" added to end of particular URI.

 

eg: https://abc.com/itsm/console needs to be https://abc.com/itsm/console/

 

My VIP consist of an APM policy which uses F5 as SAML SP with external IDP to authenticate user session.

 

I used following irule to do the job, however it is not working as expected. Instead of adding the / to the URI I'm getting random URIs such as https://abc.com/itsm/console/login/logon.do

 

However if I manually enter https://abc.com/itsm/console/ I don't get such re directions and get to the expected webpage.

 

when HTTP_REQUEST {

  if { [HTTP::uri] starts_with "/itim/console" } {

    HTTP::uri [string map {"/itim/console" "/itim/console/"} [HTTP::uri]]

  }

}

 

Appreciate your help to correct my irule, also want your input on how to match multiple URIs and add / as there are 2 more URIs that I need to add / in the end

 

 

2 Replies

  • First, using starts_with is not a good idea - you need an exact match:

    e.g. the request is

    https://abc.com/itsm/console/ 

     

    This matches the starts_with "/itim/console"

    so the string map occurs and replaces "/itim/console" with "/itim/console/"...

     

    HTTP::uri is now /itsm/console//

     

    If this is an APM portal, then maybe use a Rewrite profile and match the specific URI you need to rewrite

     

  • Hi wick54,

    Can you try this?

    when HTTP_REQUEST {
    	switch -glob [HTTP::uri] {
    		"/itim/console" - 
    		"/itim/uri2" -
    		"/uri3" {
    			HTTP::uri "[HTTP::uri]/"
    		}
    	}
    }