Forum Discussion

Vince_Beltz_959's avatar
Vince_Beltz_959
Icon for Nimbostratus rankNimbostratus
Feb 12, 2009

HTTP Redirect

What I need to do is rewrite any incoming HTTP request for specific domains that has either nothing or just a / after the TLD into the form http://www.domain.com/label/ws/index. Requests that have a longer URI should be passed without change. The rule has to be specific for each domain instead of just pasting the domain into the URI because they don't always match (the first elseif is for domainb pointing to a labelx). Using the iRule editor, I'm getting parse errors on lines 5 and 11 (syntax 112). I'm sure I'm making some kind of very basic mistake - help?

 

 

when HTTP_REQUEST {

 

 

[ string tolower [HTTP::host] ]

 

 

if { ( [HTTP::host] ends_with "domaina.com" ) and ( string length [HTTP::uri] < 2 ) } {

 

 

HTTP::redirect "http://www.domaina.com/labela/ws/index"

 

 

}

 

 

elseif { ( [HTTP::host] ends_with "domainb.com" ) and ( string length [HTTP::uri] < 2 ) } {

 

 

HTTP::redirect "http://www.domainb.com/labelx/ws/index"

 

 

}

 

 

elseif { ( [HTTP::host] ends_with "domainc.com" ) and ( string length [HTTP::uri] < 2 ) } {

 

 

HTTP::redirect "http://www.domainc.com/labelc/ws/index"

 

 

}

 

 

}

 

2 Replies

  • The URI can never be empty, it is always at least "/". So rather than doing the string length thing just test for [HTTP::uri] equal to "/". The rest of your syntax looks fine, so it's probably just a bracket out of place (elsif gives me fits for some reason with bracketing).

     

     

    Denny
  • Been adding/removing delimiters for a while, trying to shave it down to something that won't throw an error, no luck so far. Best I can get is a "line 11: [undefined procedure: elseif] [elseif { ( [HTTP::host] ends_with "domainb.com" ) and ( [HTTP::uri] equals "/" ) } {" (no complaint about the almost identical line 17, or line 5).