Forum Discussion

KJ_50941's avatar
KJ_50941
Icon for Nimbostratus rankNimbostratus
May 14, 2015

Redirect Irule help

current irule for this app is as below. both test and test 2 resolves to 192.168.192.1=example.com when HTTP_REQUEST { if { [HTTP::uri] eq "/" } { HTTP::redirect https://[HTTP::host]/test } }

 

however if request comes to /test 2 should go to example.com/test2 and /test goes to examle.com/test.

 

will this works? Will below works?

 

when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "test" } { HTTP::redirect "https://example.com/[HTTP::uri]"

 

else

 

{ [string tolower [HTTP::host]] eq "test2" } { HTTP::redirect "https://example.com/[HTTP::uri]"

 

} }

 

thank you

 

  • Your iRule is correct. Please try this.

            when HTTP_REQUEST { 
    if { ( [string tolower [HTTP::uri]] starts_with "/test1" ) or ( [string tolower [HTTP::uri]] starts_with "/test2" ) } { 
        HTTP::redirect "https://example.com[HTTP::uri]"
    } 
    

    }

    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      i think forward slash (/) between fqdn and uri is not needed. HTTP::redirect "https://example.com[HTTP::uri]"
  • e.g.

    when HTTP_REQUEST {
      if { [HTTP::uri] equals "/" } {
        switch -glob [HTTP::host] {
          "*test1*" {
            HTTP::redirect "http://example.com/test1"
          }
          "*test2*" {
            HTTP::redirect "http://example.com/test2"
          }
          default {
             Host does not contain test1 or test2
             Do something
          }
        }
      } else {
         URI is not root (/)
         Do something
      }
    }
    
  • e.g.

    when HTTP_REQUEST {
      if { [HTTP::uri] equals "/" } {
        switch -glob [HTTP::host] {
          "*test1*" {
            HTTP::redirect "http://example.com/test1"
          }
          "*test2*" {
            HTTP::redirect "http://example.com/test2"
          }
          default {
             Host does not contain test1 or test2
             Do something
          }
        }
      } else {
         URI is not root (/)
         Do something
      }
    }