Forum Discussion

davidfisher's avatar
Jun 14, 2020

irule to redirect directly to en uri along with https

Hi

We have multiple requirements to improve the page load times. The second part is easy but the first one sounds tricky.

Can the https redirect be done in a way that the website directly goes to /en along with https?

So if user comes in on :

http://domain.com -----> https://domain.com/en

and if :

http://domain.com/ar -----> https://domain.com/ar

or else for anything else.

http://domain.com/ -----> https://domain.com/en

I right now have the following but I don't know how to get the first part here..

when HTTP_REQUEST {
 switch -glob [string tolower [HTTP::uri]] {
  "/ar" { HTTP::redirect "https://domain.com/ar/" }  
  default { HTTP::redirect "https://domain.com/en/" }
 }
}

Thanks!

2 Replies

  • Hello,

     

    Please try below iRule, this should work.

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] starts_with "/ar"} {

      HTTP::redirect https://domain/ar

    } else {

      HTTP::redirect https://domain.com/en

    }

    }

     

    Hope it works,

    Mayur

  • Have you tried above iRule ? As per given requirement, it is working in my lab setup so it should work for you as well. Just check what condition are you matching for URI match? Are you matching starts_with or contains?

     

    Also LTM policy would be also a option to achieve this requirement.

     

    Hope it helps!

    Mayur