Forum Discussion

Will_12716's avatar
Will_12716
Icon for Nimbostratus rankNimbostratus
Jul 17, 2008

Site Redirect with Irule

We have a situation that requires us to redirect traffic to a different port than port 80.

 

 

For example, we need to take any requests to http://www.mysite.com and redirect to http://www.mysite.com:9901/MRBS/

 

 

It is setup on websphere in a cluster.

 

 

We have a virtual server that load balances to two servers.

 

 

9 Replies

  • If you configure a pool with the IP address(es) of the server(s) and create a VIP with port translatio enabled, LTM will translate the port from the VIP port to the pool member port automatically. If you want to rewrite the URI, you can use the HTTP::uri command. If you want to redirect the client, you can use HTTP::redirect.

     

     

    Aaron
  • The port translation was enabled but noticed we did not have the virtual server responding on port 80. I made that change and it worked. Now we are having this issue:

     

     

    When a client types in http://service.mysite.com, I want to be able to redirect that request to http://service.mysite.com/SHCM/

     

     

    I have tried this IRULE:

     

     

    when HTTP_REQUEST {

     

    if {[HTTP::uri] equals {http://service.mysite.com}} {HTTP::uri {http://service.mysite.com/SHCM/}

     

    }

     

    }

     

     

    Can anyone help with this?
  • brice's avatar
    brice
    Icon for Nimbostratus rankNimbostratus
    I would try the following. You might want to think about redirecting from service.mysite.com to www.mysite.com/SHCM, and not service.mysite.com/SHCM, but I have created the rule so both host and uri are very portable. The key is using "contains" instead of "equals" I think. See below...

      
     when HTTP_REQUEST {  
     set uri [HTTP::uri]  
     set host [HTTP::host]  
     if { [HTTP::host] contains "service.mysite.com" } {  
     set uri "SHCM"  
     }  
     HTTP::respond 301 Location "http://$host$uri"  
     }  
     
  • Oh, one other comment, directed to brices21:

     

     

    Due to the way iRules cache the values of things, storing stuff like [HTTP::uri] in a variable and referencing that variable is actually slower than just always using [HTTP::uri]. It's weird, but true (unless things have changed recently). There have been a few threads about this previously, but I'm having trouble finding them right now.
  • We are getting there but not yet.

     

     

    We have a Virtual Server pointing to 192.168.0.179:80 that has a pool with two members that use 192.168.0.79:9081 and 192.168.0.80:9081. I believe we are having the issue when the redirect happens it does not use port 9081. We can put in redirect to www.google.com and it works.

     

     

    We basically want to have http://service.mysite.com to add the uri SHCM.
  • The redirect should end up causing a new connection to the same VIP, so my guess is that the VIP isn't configured to use the pools properly (maybe port translation isn't setup right?).
  • We fixed the issue.

     

     

    Here is what we had to do:

     

     

    when HTTP_REQUEST {

     

    if {([HTTP::host] equals "selfservice.mysite.com") and

     

    ([HTTP::uri] equals "/")}

     

    {

     

    HTTP::uri "http://selfservice.mysite.com/SHCM/"

     

    }

     

    }

     

     

    Thanks to everyone for their help.
  • man, I tried this iRule and the LTM will not take it... I get an error...

     

     

     

    01070151:3: Rule [Labcorp_Selfpay.shps.com] error:

     

    line 3: [missing a script after "if"] [ ]

     

    line 4: [undefined procedure:

     

    HTTP::redirect "http://selfpay.shps.com/LCSP"

     

    ] [{

     

    HTTP::redirect "http://selfpay.shps.com/LCSP"

     

    } ]

     

     

     

    Anyone have any ideas?

     

  • I would guess you have a simple syntax error. Can you post the rule you're testing? It looks like the rule changed from when you posted previously with the one that you're seeing an error with.

     

     

    Aaron