Forum Discussion

chungyu_16122's avatar
chungyu_16122
Icon for Altostratus rankAltostratus
Mar 28, 2012

iRule redirects for HTTP::uri

Hi all

 

 

I wrote a irule for some simple HTTP redirect but found that a single / inserted by the user was casue the rule to break.

 

 

For example user tries to reach french.school.ca/students and I redirect to http:://www.school.ca/fr/student.

 

 

 

But if the user tries french.school.ca/students/ then the irule would not work.

 

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "francais.mcgill.ca" and [HTTP::uri] equals "/students" } {

 

HTTP::redirect "http://www.mcgill.ca/fr/students"

 

}

 

}

 

 

 

I tried the equals "/students/ as well, but that did not work.

 

 

 

Can anyone shed some light on the syntax I could use.

 

 

 

 

thanks

 

 

 

Chung

 

 

1 Reply

  • wlopez's avatar
    wlopez
    Icon for Cirrocumulus rankCirrocumulus
    Have you tried replacing the "equals" operator with "starts_with"?

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::host] equals "francais.mcgill.ca" and [HTTP::uri] starts_with "/students" } {

     

    HTTP::redirect "http://www.mcgill.ca/fr/students"

     

    }

     

    }