Forum Discussion

DM_5174's avatar
DM_5174
Icon for Nimbostratus rankNimbostratus
Jun 11, 2008

HTTP to another URL redirection does not work

Hi All,

 

 

I have the following i-rule that does not work and I have no clue what the problem is, and if its with the irule or the LTM (virtual server profile etc...)

 

 

The rule apply without errors, however when i specify "/newapp", after the main URI, it does not redirect to www.newsite.com/home/index.html

 

 

All the help is much appreciated!

 

 

 

when HTTP_REQUEST {

 

if { ([HTTP::host] equals "www.oldsite.com") && ([string tolower [HTTP::uri]] equals "/newapp") } {

 

HTTP::redirect "www.newsite.com/home/index.html"

 

} else {

 

pool WEB_POOL7

 

}

 

}

 

 

 

 

Thank you in advance!!
  • It could be that it's not hitting the first IF statement and simply going to pool WEB_POOL7

    In that case you might want to add the following debug statement to verify.

    Add the following before HTTP::redirect statement

    when HTTP_REQUEST {

    if { ([HTTP::host] equals "www.oldsite.com") && ([string tolower [HTTP::uri]] equals "/newapp") } {

    log local0. "The url is [HTTP::host][HTTP::uri]"

    HTTP::redirect "www.newsite.com/home/index.html"

    } else {

    pool WEB_POOL7

    log local0. "This Pool WEB_PPOL7 was selected "

    }

    }

    This will log the a message in /var/log/ltm file and when you run it will you know which part of the iRule it was executed. If you see the second message then you know it's not hitting the IF statement.

    OR

    you can rewrite the entire iRule in 3 other ways(...actually there is a 4th way but I think I overkilled this one 🙂 ...)

    Other Way 1

      
      when HTTP_REQUEST {  
         if { [HTTP::host] = "www.oldsite.com" } {  
            if {[HTTP::uri] = "/newapp" } { HTTP::redirect "http://www.newsite.com/home/index.html" }  
          } else {  
          pool WEB_POOL7  
          }  
         }  
      }  
      

    Other Way 2

      
      when HTTP_REQUEST {  
        set url [HTTP::host][HTTP::uri]  
        
         if { $url = "www.oldsite.com/newapp" } {  
           HTTP::redirect "http://www.newsite.com/home/index.html"  
          } else {  
          pool WEB_POOL7  
          }  
      }  
      

    Other Way 3

      
      when HTTP_REQUEST {  
         set url [HTTP::host][HTTP::uri]  
         switch -glob $url {  
           "www.oldsite.com/newapp" { HTTP::redirect "http://www.newsite.com/home/index.html" }  
           default { pool WEB_POOL7 }  
           }  
      } 
     

    Hope this helps

    CB

  • Thank you CB! I will try out option 2 with a debug and see what happens.

     

    This option makes the most sense to me and seems to be the easiest to implement.

     

    I will let you know what happens....

     

     

    -A
  • I tried option 1 and 2 but does not work. Getting syntax error. Option 3 does work, however it is case senstive. So if you put "NeWaPP" or "Newapp" it does not work. It does work if you use lower case and put "newapp"...

     

     

    is there a way to make this so that it works with either capital or lower case letters?

     

     

    Thanks again!
  • I never took the time to validate my code. Now that I have a second look at it, I think I fixed it adding in the portion to lowercase the evalulation.

     

     

    Here is the items fixed again also handling the capital and lower case letters

     

    Other Way 1 fixed

     

     
     when HTTP_REQUEST { 
     if { [HTTP::host] eq "www.oldsite.com" }{ 
     if {[string tolower [HTTP::uri]] eq "/newapp" }{  
     HTTP::redirect "http://www.newsite.com/home/index.html"  
     } else {         
       pool web_POOL7 
     } 
     } 
     } 
     

     

     

    Other Way 2

     

     

     
     when HTTP_REQUEST { 
     set url [string tolower [HTTP::host][HTTP::uri]] 
     if { $uri eq "www.oldsite.com/newapp" }{ 
     HTTP::redirect "http://www.newsite.com/home/index.html"  
     } else {         
       pool web_POOL7 
     } 
     } 
     

     

     

     

    Other way 3

     

     
       when HTTP_REQUEST {        
     set url [string tolower [HTTP::host][HTTP::uri]]        
     switch -glob $url {          
     "www.oldsite.com/newapp" { HTTP::redirect "http://www.newsite.com/home/index.html" }          
     default { pool web_POOL7 } 
     } 
     }  
     

     

     

    CB