Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Jun 18, 2009

Simple redirect with query not working

I am trying to put a simple redirect in place that simply appends a subdomain if the URI is specific, basically I want to say if the URI is:

http://ourdomain.com/the/learningcenters/center/?msid=14

Then redirect to:

http://legacy.ourdomain.com/the/learningcenters/center/?msid=14

We are just adding legacy. to the url. I have put the following iRule in place, but it won't redirect - is this because of the ?msid=14 ? We have a few of these and they differ:

?msid=14

?msid=15

?msid=16

Here's my iRule:

   
 when HTTP_REQUEST {    
 set h [HTTP::host]    
 set u [HTTP::uri]    
 switch -glob $h {    
 "http://ourdomain.com/the/learningcenters/center/?msid=14" {    
 HTTP::redirect    "http://legacy.ourdomain.com/the/learningcenters/center/?msid=14"    
 }    
 }    
 }

Can anyone help?
  • Try this:

     
     when HTTP_REQUEST { 
       if { "[HTTP::host][HTTP::path]" equals "ourdomain.com/the/learningcenters/center/" } { 
         HTTP::redirect "http://legacy.[HTTP::host][HTTP::uri]" 
       } 
     } 
     
  • Hmm....that will redirect all requests going to /the/learningcenters/center/ - we have other content that is there that we can't redirect to legacy.

     

     

    Do you know if there is a reason why this redirect won't work based on the ?msid=14?
  • Ah, I see ... What about this:

     
     when HTTP_REQUEST {  
        if { [string match "ourdomain.com/the/learningcenters/center/?msid=*" "[HTTP::host][HTTP::uri]"] } {  
          HTTP::redirect "http://legacy.[HTTP::host][HTTP::uri]"  
        }  
      } 
     

    Your iRule doesn't work because $h in your switch contains only "ourdomain.com" ([HTTP::host]) but not "/the/learningcenters/center/?msid=14"
  • Wow that is exactly what I wanted - thanks!!!! It all makes sense now...I really appreciate your help!