# IRule change URI only when traffic coming from external

**URL:** <https://community.f5.com/t/irule-change-uri-only-when-traffic-coming-from-external/60214>\
**Category:** Technical Forums\
**Tags:** irules, ltm, application-delivery, uri\
**Created:** [November 26, 2019, 7:37am UTC](https://community.f5.com/t/irule-change-uri-only-when-traffic-coming-from-external/60214 "2019-11-26T07:37:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgaigl](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kgaigl](https://community.f5.com/u/kgaigl)\
**Post date:** [November 26, 2019, 7:37am UTC](https://community.f5.com/t/irule-change-uri-only-when-traffic-coming-from-external/60214/1 "2019-11-26T07:37:00Z")

</div>

Hello,

need some help:

I’ve got the need to rewrite URI from [domain.com/internal](http://domain.com/internal) to [domain.com/home](http://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

---

<div class="post-metadata">

**Author:** ![Enes\_Afsin\_Al](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/enes_afsin_al/32/15359_2.png) [@Enes\_Afsin\_Al](https://community.f5.com/u/Enes_Afsin_Al)\
**Post date:** [November 26, 2019, 8:14am UTC](https://community.f5.com/t/irule-change-uri-only-when-traffic-coming-from-external/60214/2 "2019-11-26T08:14:16Z")

</div>

Hi kgaigl,

```tcl
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"
			}
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![kgaigl](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kgaigl](https://community.f5.com/u/kgaigl)\
**Post date:** [November 26, 2019, 8:39am UTC](https://community.f5.com/t/irule-change-uri-only-when-traffic-coming-from-external/60214/3 "2019-11-26T08:39:04Z")

</div>

Hi eaa,

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

one question: in another IRule there is a string:

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

```

could I use the expression “private\_net” to shorten the rule?

---

<div class="post-metadata">

**Author:** ![Enes\_Afsin\_Al](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/enes_afsin_al/32/15359_2.png) [@Enes\_Afsin\_Al](https://community.f5.com/u/Enes_Afsin_Al)\
**Post date:** [November 26, 2019, 8:50am UTC](https://community.f5.com/t/irule-change-uri-only-when-traffic-coming-from-external/60214/4 "2019-11-26T08:50:21Z")

</div>

Yes, you can use instead of switch statement.

```tcl
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"
		}
	}
}

```
