Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Jan 12, 2010

Catch a specific URL and redirect it

I have an existing iRule which uses a switch statement to catch a request no matter the case (string tolower) and redirect.

For some reason, the iRule is not catching and redirecting - I simply want to do this:

http://oursite.com/EventOverview.aspx?Event=some2010

Should redirect to:

http://ourothersite.com/events/event-name.aspx

Can anyone tell me why this below wouldn't work?

  
  when HTTP_REQUEST {   
     switch -glob [string tolower [HTTP::uri]] {    
       "/EventOverview.aspx?Event=some2010" {   
        HTTP::redirect "http://ourothersite.com/events/event-name.aspx"   
      }   
    }   
  }  
  

7 Replies

  • You are converting the URI to lower case and then comparing it to a mixed case string and that will always fail. Lower case your match string and all should be good.

    when HTTP_REQUEST { 
       switch -glob [string tolower [HTTP::uri]] { 
         "/eventoverview.aspx?event=some2010" { 
           HTTP::redirect "http://ourothersite.com/events/event-name.aspx" 
         } 
       } 
     }

    -Joe
  • Yikes I should have caught that - cloudy thinking yesterday.

     

     

    Thanks again for your help!
  • How can I add an or, so that I can look for 1 of 2 URIs and redirect to one? http://oursite/1 or http://oursite/2 to http://oursite/3. I'm trying to keep this simple as I have many pairs to do this with on the same VS.

     

     

    /1 or /2 to /3.

     

    /4 or /5 to /6.

     

    /7 or /8 to /9, and so on.

     

     

    Thanks
  • e.g.

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            switch [string tolower [HTTP::uri]] {
                    "/1" -
                    "/2" { HTTP::redirect "http://[HTTP::host]/3" }
                    "/4" -
                    "/5" { HTTP::redirect "http://[HTTP::host]/6" }
                    "/7" -
                    "/8" { HTTP::redirect "http://[HTTP::host]/9" }
                    default {  do something }
            }
    }
    }
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/1
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/3
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/2
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/3
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/4
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/6
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/5
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/6
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/7
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/9
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/8
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/9
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/other
    HTTP/1.1 404 Not Found
    Date: Mon, 12 Dec 2011 14:17:53 GMT
    Server: Apache/2.2.3 (CentOS)
    Connection: close
    Content-Type: text/html; charset=iso-8859-1
    
    
  • e.g.

    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            if {[class match -- [string tolower [HTTP::uri]] equals uri_redirect]} {
                    HTTP::redirect "http://[HTTP::host][class match -value [string tolower [HTTP::uri]] equals uri_redirect]"
            }
    }
    }
    [root@ve1023:Active] config  b class uri_redirect list
    class uri_redirect {
       {
          "/1" { "/3" }
          "/2" { "/3" }
          "/4" { "/6" }
          "/5" { "/6" }
          "/7" { "/9" }
          "/8" { "/9" }
       }
    }
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/1
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/3
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/2
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/3
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/4
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/6
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/5
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/6
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/7
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/9
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/8
    HTTP/1.0 302 Found
    Location: http://172.28.19.79/9
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/other
    HTTP/1.1 404 Not Found
    Date: Mon, 12 Dec 2011 14:23:03 GMT
    Server: Apache/2.2.3 (CentOS)
    Connection: close
    Content-Type: text/html; charset=iso-8859-1
    
    
  • Nitass,

     

     

    It worked perfectly. Thanks again for the help.

     

     

    Dave