Forum Discussion

21 Replies

  • Hi,

    Here is the iRule you need :

    when HTTP_REQUEST {
        if {([string tolower [HTTP::uri]] contains "/xyz") and [string to lower [HTTP::host]] equals "abc"}{
            HTTP::redirect http://abc:40001;
        }
    }
    
    • siyadh_121603's avatar
      siyadh_121603
      Icon for Nimbostratus rankNimbostratus
      Hi Thomas, Thank you for your quick response. Is there missing any syntax...? Because we are not able to save it from iRule Editor (it shows red).
  • Hi,

    Here is the iRule you need :

    when HTTP_REQUEST {
        if {([string tolower [HTTP::uri]] contains "/xyz") and [string to lower [HTTP::host]] equals "abc"}{
            HTTP::redirect http://abc:40001;
        }
    }
    
    • siyadh_121603's avatar
      siyadh_121603
      Icon for Nimbostratus rankNimbostratus
      Hi Thomas, Thank you for your quick response. Is there missing any syntax...? Because we are not able to save it from iRule Editor (it shows red).
  • I'm sorry typo mistake due to autocorrect... This is not "to lower" but "tolower".

    Sorry.
    when HTTP_REQUEST {
        if {([string tolower [HTTP::uri]] contains "/xyz") and [string tolower [HTTP::host]] equals "abc"}{
            HTTP::redirect http://abc:40001;
        }
    }
    
    • siyadh_121603's avatar
      siyadh_121603
      Icon for Nimbostratus rankNimbostratus
      Hi Thomas, Appreciated your quick reply. But it is redirecting to https and getting server error 404.
    • LyonsG_85618's avatar
      LyonsG_85618
      Icon for Cirrostratus rankCirrostratus
      You may prefer to have: starts_with "/xyz" If you use contains iRule will check the whole URI for /xyz? i.e. it will not only match http://abc/xyz but also http://abc/123/456/xyz
  • I'm sorry typo mistake due to autocorrect... This is not "to lower" but "tolower".

    Sorry.
    when HTTP_REQUEST {
        if {([string tolower [HTTP::uri]] contains "/xyz") and [string tolower [HTTP::host]] equals "abc"}{
            HTTP::redirect http://abc:40001;
        }
    }
    
    • siyadh_121603's avatar
      siyadh_121603
      Icon for Nimbostratus rankNimbostratus
      Hi Thomas, Appreciated your quick reply. But it is redirecting to https and getting server error 404.
    • LyonsG_85618's avatar
      LyonsG_85618
      Icon for Cirrostratus rankCirrostratus
      You may prefer to have: starts_with "/xyz" If you use contains iRule will check the whole URI for /xyz? i.e. it will not only match http://abc/xyz but also http://abc/123/456/xyz
  • But it is redirecting to https and getting server error 404.

    can you post the port 80 and port 40001 virtual servers and their pools configurations?

     tmsh list ltm virtual (name)
     tmsh list ltm pool (name)
    
    • siyadh_121603's avatar
      siyadh_121603
      Icon for Nimbostratus rankNimbostratus
      Hi Nitass, Please find the below details. ------------------------------------------- 40001: ------------------------------------------- ltm virtual FIM_40001 { destination 172.16.215.32:40001 ip-protocol tcp mask 255.255.255.255 pool FIM_40001 profiles { tcp { } } source 0.0.0.0/0 translate-port disabled vlans-disabled } ltm pool FIM_40001 { members { 172.16.225.165:40001 { address 172.16.225.165 session monitor-enabled state up } 172.16.225.166:40001 { address 172.16.225.166 session user-disabled state up } } monitor gateway_icmp } ------------------------------------------- HTTP: ------------------------------------------- ltm virtual FIM_HTTP_http_virtual { app-service /Common/FIM_HTTP.app/FIM_HTTP destination /Common/172.16.215.32:http ip-protocol tcp mask 255.255.255.255 pool FIM_HTTP_pool profiles { /Common/tcp { } FIM_HTTP_http_profile { } } rules { /Common/FIM /Common/FIM-4001 /Common/FIM-4002 } source 0.0.0.0/0 vlans-disabled } ltm pool FIM_HTTP_pool { app-service /Common/FIM_HTTP.app/FIM_HTTP load-balancing-mode least-connections-member members { /Common/172.16.225.165:http { address 172.16.225.165 app-service /Common/FIM_HTTP.app/FIM_HTTP session monitor-enabled state up } /Common/172.16.225.166:http { address 172.16.225.166 app-service /Common/FIM_HTTP.app/FIM_HTTP session user-disabled state up } } monitor FIM_HTTP_http_monitor slow-ramp-time 300 }
  • But it is redirecting to https and getting server error 404.

    can you post the port 80 and port 40001 virtual servers and their pools configurations?

     tmsh list ltm virtual (name)
     tmsh list ltm pool (name)
    
    • siyadh_121603's avatar
      siyadh_121603
      Icon for Nimbostratus rankNimbostratus
      Hi Nitass, Please find the below details. ------------------------------------------- 40001: ------------------------------------------- ltm virtual FIM_40001 { destination 172.16.215.32:40001 ip-protocol tcp mask 255.255.255.255 pool FIM_40001 profiles { tcp { } } source 0.0.0.0/0 translate-port disabled vlans-disabled } ltm pool FIM_40001 { members { 172.16.225.165:40001 { address 172.16.225.165 session monitor-enabled state up } 172.16.225.166:40001 { address 172.16.225.166 session user-disabled state up } } monitor gateway_icmp } ------------------------------------------- HTTP: ------------------------------------------- ltm virtual FIM_HTTP_http_virtual { app-service /Common/FIM_HTTP.app/FIM_HTTP destination /Common/172.16.215.32:http ip-protocol tcp mask 255.255.255.255 pool FIM_HTTP_pool profiles { /Common/tcp { } FIM_HTTP_http_profile { } } rules { /Common/FIM /Common/FIM-4001 /Common/FIM-4002 } source 0.0.0.0/0 vlans-disabled } ltm pool FIM_HTTP_pool { app-service /Common/FIM_HTTP.app/FIM_HTTP load-balancing-mode least-connections-member members { /Common/172.16.225.165:http { address 172.16.225.165 app-service /Common/FIM_HTTP.app/FIM_HTTP session monitor-enabled state up } /Common/172.16.225.166:http { address 172.16.225.166 app-service /Common/FIM_HTTP.app/FIM_HTTP session user-disabled state up } } monitor FIM_HTTP_http_monitor slow-ramp-time 300 }
  • Hi

     

    Should redirect not be:

     

    HTTP::redirect "http://abc:40001"

     

    Graham

     

  • can you try to set event priority and disable all after redirection?

    priority

    https://devcentral.f5.com/wiki/iRules.priority.ashx

    event disable

    https://devcentral.f5.com/wiki/iRules.event.ashx

    e.g.

    // config
    
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 63
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST priority 100 {
      if { [HTTP::path] starts_with "/xyz" } {
        HTTP::redirect "http://[HTTP::host]:40001/"
        event disable all
      }
    }
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar40001
    ltm virtual bar40001 {
        destination 172.28.24.10:40001
        ip-protocol tcp
        mask 255.255.255.255
        pool foo40001
        profiles {
            tcp { }
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 64
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo40001
    ltm pool foo40001 {
        members {
            200.200.200.101:40001 {
                address 200.200.200.101
            }
        }
    }
    
    // test
    
    [root@ve11a:Active:In Sync] config  curl -IL http://172.28.24.10/xyz/something
    HTTP/1.0 302 Found
    Location: http://172.28.24.10:40001/
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    HTTP/1.1 200 OK
    Date: Sat, 16 Aug 2014 08:24:04 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Sun, 09 Feb 2014 08:39:51 GMT
    ETag: "41879c-59-2a9c23c0"
    Accept-Ranges: bytes
    Content-Length: 89
    Connection: close
    Content-Type: text/html; charset=UTF-8
    
    
    • siyadh_121603's avatar
      siyadh_121603
      Icon for Nimbostratus rankNimbostratus
      Hi Nitass, Thank you for your guidance and support. This iRules works fine when HTTP_REQUEST { if {([string tolower [HTTP::uri]] contains "/xyz") and [string tolower [HTTP::host]] equals "abc"}{ HTTP::redirect http://abc:40001; } }
    • Thomas_Gobet's avatar
      Thomas_Gobet
      Icon for Nimbostratus rankNimbostratus
      Be careful on using contains, LyonsG was right. You may prefere using starts_with instead of contains, you'll be sure that you won't have "false matches".
  • can you try to set event priority and disable all after redirection?

    priority

    https://devcentral.f5.com/wiki/iRules.priority.ashx

    event disable

    https://devcentral.f5.com/wiki/iRules.event.ashx

    e.g.

    // config
    
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 63
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST priority 100 {
      if { [HTTP::path] starts_with "/xyz" } {
        HTTP::redirect "http://[HTTP::host]:40001/"
        event disable all
      }
    }
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar40001
    ltm virtual bar40001 {
        destination 172.28.24.10:40001
        ip-protocol tcp
        mask 255.255.255.255
        pool foo40001
        profiles {
            tcp { }
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 64
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo40001
    ltm pool foo40001 {
        members {
            200.200.200.101:40001 {
                address 200.200.200.101
            }
        }
    }
    
    // test
    
    [root@ve11a:Active:In Sync] config  curl -IL http://172.28.24.10/xyz/something
    HTTP/1.0 302 Found
    Location: http://172.28.24.10:40001/
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    HTTP/1.1 200 OK
    Date: Sat, 16 Aug 2014 08:24:04 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Sun, 09 Feb 2014 08:39:51 GMT
    ETag: "41879c-59-2a9c23c0"
    Accept-Ranges: bytes
    Content-Length: 89
    Connection: close
    Content-Type: text/html; charset=UTF-8
    
    
    • siyadh_121603's avatar
      siyadh_121603
      Icon for Nimbostratus rankNimbostratus
      Hi Nitass, Thank you for your guidance and support. This iRules works fine when HTTP_REQUEST { if {([string tolower [HTTP::uri]] contains "/xyz") and [string tolower [HTTP::host]] equals "abc"}{ HTTP::redirect http://abc:40001; } }
    • Thomas_Gobet's avatar
      Thomas_Gobet
      Icon for Nimbostratus rankNimbostratus
      Be careful on using contains, LyonsG was right. You may prefere using starts_with instead of contains, you'll be sure that you won't have "false matches".