Forum Discussion

chungyu_16122's avatar
chungyu_16122
Icon for Altostratus rankAltostratus
Aug 01, 2011

How to append to URI

Hi eveyone

 

 

We have parts of our webite that are french, and when a user has access a http://francais.mcgill.ca, I need to append a /fr to certain sites.

 

 

 

I have created this irule but can not get it to work properly.

 

 

 

when HTTP_REQUEST {

 

if { [string tolower [HTTP::host]] equals "francais.mcgill.ca" \

 

and [string tolower [HTTP::uri]] equals "science"} {

 

HTTP::uri "[HTTP:uri]/science/fr"

 

}

 

}

 

 

 

 

I have seen similar post regarding appending URI and based the rule off them but the 4th line is not accepted.

 

 

 

Thanks

 

 

 

Chung

 

4 Replies

  • The first issue I see is the test...

     

    [string tolower [HTTP::uri]] equals "science"

     

     

    This should probably say...

     

    [string tolower [HTTP::uri]] starts_with "/science"

     

     

    Note the leading slash! The leading slash will always be included in HTTP:uri or HTTP:path.

     

  • 
    when HTTP_REQUEST {
       if { [string tolower [HTTP::host]] eq "francais.mcgill.ca" } {
            if { [string tolower [HTTP::uri]] starts_with "/science" } {
                HTTP::uri "/science/fr/[string range [HTTP::uri] 11 end]" }
        }
    }
    

    That should hopefully work.
  • Thanks alot, i will try it out, however, I forsee that I will have multiple sites that require the /fr but not every site. I have used matchclass operator to send traffic to different servers based off class list, could I do something similar? where I have a list of sites that need to have the /fr appended?

     

     

    Chung
  • Hi Chungu,

     

    Yes you should be able to do that. If you are using v10 then you can use the class command (http://devcentral.f5.com/wiki/iRules.class.ashx)

     

     

    Bhattman