Forum Discussion

Mike_61640's avatar
Mike_61640
Icon for Nimbostratus rankNimbostratus
Feb 20, 2009

Redirect based on URI content

I have a couple of different requirements for a redirect.

 

 

I'm trying to first check the host name and if it doesn't include www in it, I need it added (i.e http://company.com should be http://www.company.com).

 

 

The second piece is that if the URI contains a "." in it then it should be redirected to a different to a diffrent host site.

 

 

Example: http://company.com/images.gif should be redirected to http://sub.company.com/imgages.gif

 

 

I'm brand new to iRules, but I have found some examples for the first part and I've been trying to hack my way through it, it just doesn't seem to be working.

1 Reply

  • Issue 1:

    This will redirect the client:

     
     if { [domain [HTTP::host] 2] equals [HTTP::host] } { 
       HTTP::redirect www.[HTTP::host] 
     } 
     

    This will just fix the header, with no change in client's perspective:

     
     if { [domain [HTTP::host] 2] equals [HTTP::host] } { 
       HTTP::header replace Host "www.[HTTP::host]" 
     } 
     

    Issue 2:

    Is this also for the same rule as Issue 1? If so, in which order should they be evaluated? it can't be sent to both www and sub.