Forum Discussion

jcline's avatar
jcline
Icon for Nimbostratus rankNimbostratus
Sep 30, 2015

I need an iRule that will search the HTTP::path for "/en/' change it to "/en-us/" and leave the rest of the path, query string intact

I need an iRule that will search the HTTP::path for "/en/' change it to "/en-us/" and leave the rest of the path, query string intact.

 

I have tried.

 

when HTTP_REQUEST { if { [string tolower [HTTP::path]] contains "/en/" } { HTTP::redirect "http://[HTTP::host]/en-us/[HTTP::query]" } }

 

and it just repeats/en-us/en-us/...then puts/en/?query string

 

I also tried

 

when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/en/"}{ HTTP::respond 302 noserver Location "http://[HTTP::host][string map {en en-us} [HTTP::uri]]" } }

 

Neither one is working for me.

 

I am trying to temporarily bandage an issue that was created by a culture change in an application. The application used to accept /en/ as a culture and marketing has sent out hundred of links that use /en/ but the application was changed to no longer accept /en/ soi they asked me to change /en/ to /en-us/

 

Any advice or help would be appreciated.

 

Thanks John

 

2 Replies

  • Try this:

    when HTTP_REQUEST {
        if { [string tolower [HTTP::uri]] starts_with "/en/" } {
            set uri [string map -nocase {"/en/" "/en-us/"} [HTTP::uri]]
            HTTP::redirect "http://[HTTP::host]${uri}"
        }
    }