For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

kgaigl's avatar
kgaigl
Icon for Cirrocumulus rankCirrocumulus
Nov 26, 2019

IRule change URI only when traffic coming from external

Hello,

 

need some help:

I've got the need to rewrite URI from domain.com/internal to domain.com/home but only when traffic comes from outside, not from inside (=private net)

 

the rewrite of the URI I could achieve with a LTM-Policy but not in combination with the second condition. Am I right?

 

Could someone help me with a IRule?

 

would be great, thanks

3 Replies

  • Hi kgaigl,

    when HTTP_REQUEST {
    	if { ([HTTP::host] equals "domain.com") and ([string tolower [HTTP::uri]] starts_with "/internal") } {
    		switch -glob [IP::client_addr] {
    			"10.*" -
    			"192.168.*" -
    			"172.16.*" -
    			"172.17.*" -
    			"172.18.*" -
    			"172.19.*" -
    			"172.20.*" -
    			"172.21.*" -
    			"172.22.*" -
    			"172.23.*" -
    			"172.24.*" -
    			"172.25.*" -
    			"172.26.*" -
    			"172.27.*" -
    			"172.28.*" -
    			"172.29.*" -
    			"172.30.*" -
    			"172.31.*" {
    				# log local0. "Host: [HTTP::host] Uri: [HTTP::uri] ClientIP: [IP::client_addr]"
    			}
    			default {
    				HTTP::redirect "https://domain.com/home"
    				# or
    				# HTTP::uri "/home"
    			}
    		}
    	}
    }
  • kgaigl's avatar
    kgaigl
    Icon for Cirrocumulus rankCirrocumulus

    Hi eaa,

    thanks a lot, but I can test it not before next week.

    one question: in another IRule there is a string:

    if {!([class match [IP::client_addr] equals private_net])}

    could I use the expression "private_net" to shorten the rule?

    • Yes, you can use instead of switch statement.

      when HTTP_REQUEST {
      	if { ([HTTP::host] equals "domain.com") and ([string tolower [HTTP::uri]] starts_with "/internal") } {
      		if { not ([class match [IP::client_addr] equals private_net]) } {
      			HTTP::redirect "https://domain.com/home"
      			# or
      			# HTTP::uri "/home"
      		}
      	}
      }