Forum Discussion

ShakN_167332's avatar
ShakN_167332
Icon for Nimbostratus rankNimbostratus
Aug 20, 2014

Need help in Irule redirection for multiple sites.

in our setup we have sites which are accessed by internal users as well as internet users via http and https. so we have created 4 VS (2 internal VS, one for http and one for https for internal users) and (2 for internet users 1 for http and one for https). our requirement is any lan user access sites via http than it should be http if lan users type https than it should redirect to http. similarly if any internet users access sites via http than it should redirect to https. this is done by 1 irule one for http to https redirection.

 

when RULE_INIT { set static::bsint "internet.abc.com" set static::sitesint "sites.internet.abc.com"

 

} when HTTP_REQUEST { if {[class match [IP::client_addr] equals InternalHosts]} { HTTP::redirect http://[HTTP::host][HTTP::uri] } else { switch -glob -- [string tolower [HTTP::host]] { "sites.abc.com" { HTTP::header replace Host $static::sitesint STREAM::disable } "abc.com" { HTTP::header replace Host $static::bsint STREAM::disable } } } } when HTTP_RESPONSE { if {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $static::sitesint}{ HTTP::header replace Location [string map "$static::sitesint $static::sitesext" [HTTP::header Location]] }

 

elseif {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $static::bsint}{ HTTP::header replace Location [string map "$static::bsint $static::bsext" [HTTP::header Location]]

 

}

 

in addition to it i need to redirect below redirection in same irule please guide me how to do this.

 

if any one access from internet to the below url

 

https://asites.abc.com/xyz/finance

 

than it should redirect to

 

http://asites.internet.abc.com/sites/finance

 

and many more sites like this.

 

please some one help me in this.thank you in advance.

 

53 Replies

  • 01070151:3: Rule [test] error: line 3: [parse error: PARSE syntax 104 {syntax error in expression " class match [HTTP::uri] equals test ": variable references require preceding $}] [{ class match [HTTP::uri] equals test }]

     

    are you sure class match command is enclosed by square brackets?

     

  • when HTTP_REQUEST { if { [HTTP::host] equals "asites.abc.com" } { if { class match [HTTP::uri] equals test } { HTTP::redirect "http://asites.abc.com[class lookup [HTTP::uri] test]" } } }

     

  • you missed square brackets around class match command.

    when HTTP_REQUEST { 
      if { [HTTP::host] equals "asites.abc.com" } { 
        if { [class match [HTTP::uri] equals test] } { 
          HTTP::redirect "http://asites.abc.com[class lookup [HTTP::uri] test]" 
        } 
      } 
    }
    
    • nitass_89166's avatar
      nitass_89166
      Icon for Noctilucent rankNoctilucent
      you may add log command (log local0.) to the irule. example is in the irule i have given above in this thread.
  • you missed square brackets around class match command.

    when HTTP_REQUEST { 
      if { [HTTP::host] equals "asites.abc.com" } { 
        if { [class match [HTTP::uri] equals test] } { 
          HTTP::redirect "http://asites.abc.com[class lookup [HTTP::uri] test]" 
        } 
      } 
    }
    
    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      you may add log command (log local0.) to the irule. example is in the irule i have given above in this thread.
  • e.g.

    when HTTP_REQUEST { 
      if { [HTTP::host] equals "asites.abc.com" } { 
        if { [class match [HTTP::uri] starts_with test] } { 
          HTTP::redirect "http://asites.abc.com[class match -value [HTTP::uri] starts_with test]" 
        } 
      } 
    }
    

    if it still does not work, try to add logging and see what you get.

    • ShakN_167332's avatar
      ShakN_167332
      Icon for Nimbostratus rankNimbostratus
      i added the logging in irule but how to check the logs where the client ip is hitting the irule and redirection is taking place. PLease let me know the cmds to troubleshoot.
    • ShakN_167332's avatar
      ShakN_167332
      Icon for Nimbostratus rankNimbostratus
      i got one more code log local0. "Incoming URI = [HTTP::uri]" if { [string tolower [HTTP::uri]] starts_with "/bseu" } { set uri [string map -nocase {"/bseu" "/sites"} [HTTP::uri]] log local0. "New URI = $uri" HTTP::uri $uri } } now client requirement changed, above code is working where it is redirecting all the sites to required uri but client wants 2 sites which is /bseu and /bseu/it should not redirect according to the code. please suggest how this can be achived
    • ShakN_167332's avatar
      ShakN_167332
      Icon for Nimbostratus rankNimbostratus
      hi can any one give me alternative code for my requirement.
  • e.g.

    when HTTP_REQUEST { 
      if { [HTTP::host] equals "asites.abc.com" } { 
        if { [class match [HTTP::uri] starts_with test] } { 
          HTTP::redirect "http://asites.abc.com[class match -value [HTTP::uri] starts_with test]" 
        } 
      } 
    }
    

    if it still does not work, try to add logging and see what you get.

    • ShakN_167332's avatar
      ShakN_167332
      Icon for Nimbostratus rankNimbostratus
      i added the logging in irule but how to check the logs where the client ip is hitting the irule and redirection is taking place. PLease let me know the cmds to troubleshoot.
    • ShakN_167332's avatar
      ShakN_167332
      Icon for Nimbostratus rankNimbostratus
      i got one more code log local0. "Incoming URI = [HTTP::uri]" if { [string tolower [HTTP::uri]] starts_with "/bseu" } { set uri [string map -nocase {"/bseu" "/sites"} [HTTP::uri]] log local0. "New URI = $uri" HTTP::uri $uri } } now client requirement changed, above code is working where it is redirecting all the sites to required uri but client wants 2 sites which is /bseu and /bseu/it should not redirect according to the code. please suggest how this can be achived