Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

iRule to redirect to new url, but retain path in URI

Anis_Bhambhani
Nimbostratus
Nimbostratus

I have been tasked with creating an irule to redirect a url but keep everything else in URI

 

Tried with the below but had no luck.

when HTTP_REQUEST { 

  if { [string tolower [HTTP::host]] equals "wwwabc.com" and [string tolower [HTTP::uri]] starts_with "/TEST/" } { 

    HTTP::respond 301 noserver Location "<https://wwwxyz.com/[string map {/TEST/ /} [string tolower [HTTP::uri]]]>"

  }

 

It should look like

Redirect From -

https://wwwabc.com/Test/getQuote.htm?campaignCode=LIDL&campaignSource=LIDL&isMyLife=true

To -

https://wwwxyz.com/Test/getQuote.htm?campaignCode=LIDL&campaignSource=LIDL&isMyLife=true

 

- Any Suggestions please?

 

 

2 REPLIES 2

cjunior
Nacreous
Nacreous

Hi,

When you " keep everything else in URI", is simple like this:

when HTTP_REQUEST { 
    if { [string tolower [HTTP::host]] eq "wwwabc.com" and [string tolower [HTTP::uri]] starts_with "/test/" } { 
        HTTP::respond 301 noserver Location "https://wwwxyz.com[HTTP::uri]"
    }
}

When you run "string tolower" you must compare values in lower case, and you don't need to run "string map" to replace anything else as you will keep originals.

A tip, on BIG-IP version 14 and later it is possible to set the HTTP code 301 to redirect in the LTM policy rule.

 

Best regards.

 

Anis_Bhambhani
Nimbostratus
Nimbostratus

Thanks for your input, it works.

Cheers