Forum Discussion

Francisco_Arach's avatar
Francisco_Arach
Icon for Nimbostratus rankNimbostratus
Feb 06, 2012

URI Rewrite

Basically what i am trying to do is to implement the following URL rewrite rules to avoid redirects that currently happen on the site, so requests going to the specified uri, go to specific URL on the back end.

 

Requests coming to:

 

 

http://connect.company.com or http://connect.company.com/ or http://connect.company.com/inspiration or http://connect.company.com/inspiration/ should all be rewritten to:

 

 

http://connect.company.com/inspiration/default.aspx

 

 

 

For http://connect.company.com/creative or http://connect.company.com/creative/ to http://connect.company.com/creative/default.aspx

 

For http://connect.company.com/intelligence or http://connect.company.com/intelligence/ to http://connect.grey.com/intelligence/default.aspx

 

For http://connect.company.com/talent or http://connect.company.com/talent/ to http://connect.company.com/talent/default.aspx

 

For http://connect.company.com/communities or http://connect.company.com/communities to http://connect.company.com/communities/default.aspx

 

 

 

The irule I have is the following:

 

 

when HTTP_REQUEST {

 

if {([HTTP::uri] equals "/") or ([HTTP::uri] equals "/inspiration" ) or ([HTTP::uri] equals "/inspiration/")} {

 

HTTP::uri "/inspiration/default.aspx"

 

}

 

elseif {([HTTP::uri] equals "/creative") or ([HTTP::uri] equals "/creative" )} {

 

HTTP::uri "/crative/default.aspx"

 

}

 

elseif {([HTTP::uri] equals "/intelligence") or ([HTTP::uri] equals "/intelligence/")} {

 

HTTP::uri "/intelligence/default.aspx"

 

}

 

elseif {([HTTP::uri] equals "/talent") or ([HTTP::uri] equals "/talent/")} {

 

HTTP::uri "/talent/default.aspx"

 

}

 

elseif {([HTTP::uri] equals "/communities") or ([HTTP::uri] equals "/communities/")} {

 

HTTP::uri "/communities/default.aspx"

 

}

 

}

 

 

 

From your perspective, will this do the trick? the reason i am asking is because the iRules statistics dont show much traffic ... not sure if the " elseif " statement will break anything.

 

2 Replies

  • it looks fine to me. by the way, don't you want to use switch instead of if/elseif?

    e.g.

    when HTTP_REQUEST {
       switch [string tolower [HTTP::uri]] {
          "/" -
          "/inspiration" -
          "/inspiration/" {
             HTTP::uri "/inspiration/default.aspx"
          }
          "/creative" -
          "/creative/" {
             HTTP::uri "/crative/default.aspx"
          }
          "/intelligence" -
          "/intelligence/" {
             HTTP::uri "/intelligence/default.aspx"
          }
          "/talent" -
          "/talent/" {
             HTTP::uri "/talent/default.aspx"
          }
          "/communities" - 
          "/communities/" {
             HTTP::uri "/communities/default.aspx"
          }
       }
    }
    
  • Thanks for the quick response!

     

    I am kinda new to iRules, did not know abou this switch command.. Will look into it..

     

     

    thanks..