Forum Discussion

RobS's avatar
RobS
Icon for Altostratus rankAltostratus
Nov 05, 2019
Solved

iRule help for two redirects based off uri with variable

Hi,

 

I'm trying to create an iRule that does the following redirects:

 

http://xxx.com/ -> https://yyy.com/find-a-provider/

http://xxx.com/Home/Physician?profileId=UserValue -> https://yyy.com/find-a-provider/physician/UserValue

 

The first redirect based on a uri of "/" is pretty straight-forward, but the second redirect that needs to repopulate the UserValue and tying it all together in one rule is where I'm struggling. Any suggestions greatly appreciated.

  • Hi RobS,

    Can you try this iRule?

    when HTTP_REQUEST {
    	switch -glob [HTTP::uri] {
    		"/" {
    			HTTP::redirect "https://yyy.com/find-a-provider/"
    		}
    		"/Home/Physician?profileId*" { 
    			set UserValue [URI::query [HTTP::uri] profileId]
    			# log local0. "profileId = $UserValue"
    			HTTP::redirect "https://yyy.com/find-a-provider/physician/$UserValue"
    		}
    	}
    }

3 Replies

  • Can be done but consider second redirection option then 1st. Let Devcentral team knows if any questions.

  • Hi RobS,

    Can you try this iRule?

    when HTTP_REQUEST {
    	switch -glob [HTTP::uri] {
    		"/" {
    			HTTP::redirect "https://yyy.com/find-a-provider/"
    		}
    		"/Home/Physician?profileId*" { 
    			set UserValue [URI::query [HTTP::uri] profileId]
    			# log local0. "profileId = $UserValue"
    			HTTP::redirect "https://yyy.com/find-a-provider/physician/$UserValue"
    		}
    	}
    }
    • RobS's avatar
      RobS
      Icon for Altostratus rankAltostratus

      Thank-you, this works great! I didn't realize I could just pull the value of profileId and thought I was going to have to parse the uri.