# Multiple http\_request iRules not working Same Virtual server

**URL:** <https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431>\
**Category:** Technical Forums\
**Tags:** application-delivery\
**Created:** [January 17, 2023, 12:15pm UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431 "2023-01-17T12:15:58Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yesh1923](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yesh1923](https://community.f5.com/u/Yesh1923)\
**Post date:** [January 17, 2023, 12:15pm UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/1 "2023-01-17T12:15:58Z")

</div>

how to merge this 2 irule

when HTTP\_REQUEST {

if { ([string tolower [HTTP::host]] equals “[energy.com](http://energy.com)”)

HTTP::respond 301 location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” Connection Close  
}  
}

when HTTP\_REQUEST {

if { ([string tolower [HTTP::host]] equals “[corporate.ndtv.com](http://corporate.ndtv.com)”)} {  
HTTP::respond 301 location “[https://www.ndtv.com](https://www.ndtv.com)” Connection Close  
}  
}

---

<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:** [January 17, 2023, 12:35pm UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/2 "2023-01-17T12:35:43Z")

</div>

Hi iyyappan321,

```tcl
when HTTP_REQUEST {
	if { [string tolower [HTTP::host]] equals "energy.com" } {
		HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
		return
	} elseif { [string tolower [HTTP::host]] equals "corporate.ndtv.com" } {
		HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
		return
	}
}

```

switch version

```tcl
when HTTP_REQUEST {
	switch [string tolower [HTTP::host]] {
		"energy.com" {
			HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
			return
		}
		"corporate.ndtv.com" {
			HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
			return
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![Yesh1923](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yesh1923](https://community.f5.com/u/Yesh1923)\
**Post date:** [January 17, 2023, 1:19pm UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/3 "2023-01-17T13:19:10Z")

</div>

when HTTP\_REQUEST {

if { ([string tolower [HTTP::host]] equals “[energy.com](http://energy.com)”)

HTTP::respond 301 location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” Connection Close  
}  
}

when HTTP\_REQUEST {

if { ([string tolower [HTTP::host]] equals “[corporate.ndtv.com](http://corporate.ndtv.com)”)} {  
HTTP::respond 301 location “[https://www.ndtv.com](https://www.ndtv.com)” Connection Close  
}  
}

when HTTP\_REQUEST {  
switch [string tolower [HTTP::host]] {  
“exxonmobil.eu” {  
HTTP::respond 301 Location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” “Connection” “Close”  
return  
}  
“corporate.exxonmobil.com.qa” {  
HTTP::respond 301 Location “[https://www.exxonmobil.com.qa](https://www.exxonmobil.com.qa)” “Connection” “Close”  
return  
}  
}  
}

when HTTP\_REQUEST {  
if { [string tolower [HTTP::host]] equals “[energy.com](http://energy.com)” } {  
HTTP::respond 301 Location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” “Connection” “Close”  
return  
} elseif { [string tolower [HTTP::host]] equals “[corporate.ndtv.com](http://corporate.ndtv.com)” } {  
HTTP::respond 301 Location “[https://www.ndtv.com](https://www.ndtv.com)” “Connection” “Close”  
return  
}  
}

much appreciate your response

one more info need - syntax for add more url

how to add these website as well -- [goodenergy.com](http://goodenergy.com),&nbsp; [oddenergy.com](http://oddenergy.com)&nbsp; etc … in below

when HTTP\_REQUEST {

if { [string tolower [HTTP::host]] equals “[energy.com](http://energy.com)” } {  
HTTP::respond 301 Location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” “Connection” “Close”  
return

&

when HTTP\_REQUEST {  
switch [string tolower [HTTP::host]] {  
“[energy.com](http://energy.com)” {  
HTTP::respond 301 Location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” “Connection” “Close”  
return

\>\>\>\>\>\>\>\>\>\>\>\>

how add multi sites in below syntax

[marketing.ndtv.com](http://marketing.ndtv.com)" as well

“[corporate.ndtv.com](http://corporate.ndtv.com)” {  
HTTP::respond 301 Location “[https://www.ndtv.com](https://www.ndtv.com)” “Connection” “Close”  
return

---

<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:** [January 17, 2023, 2:32pm UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/4 "2023-01-17T14:32:17Z")

</div>

```tcl
when HTTP_REQUEST {
	switch [string tolower [HTTP::host]] {
		"energy.com" -
		"goodenergy.com" -
		"oddenergy.com" {
			HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
			return
		}
		"corporate.ndtv.com" -
		"marketing.ndtv.com" {
			HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
			return
		}
	}
}

```

You can review the article at the link for switch command usage.

> **[switch](https://clouddocs.f5.com/api/irules/switch.html)**

---

<div class="post-metadata">

**Author:** ![Yesh1923](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yesh1923](https://community.f5.com/u/Yesh1923)\
**Post date:** [January 17, 2023, 4:04pm UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/5 "2023-01-17T16:04:55Z")

</div>

hi enes

i will test this rule will come back if faced any issue

thanks agian for your support&nbsp; !!!

---

<div class="post-metadata">

**Author:** ![Hooni\_L](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@Hooni\_L](https://community.f5.com/u/Hooni_L)\
**Post date:** [January 18, 2023, 1:47am UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/6 "2023-01-18T01:47:57Z")

</div>

Hi

If you share one more method, you can also leverage datagroup.

```tcl
when HTTP_REQUEST {
	if { class match [string tolower [HTTP::host]] equals DATAGROUP-NAME } {
		HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
		return
	} elseif { class match [string tolower [HTTP::host]] equals DATAGROUP-NAME } {
		HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
		return
	}
}

```

DATAGROUP-NAME Include

Type String

String :

[energy.com](http://energy.com)

> **[Good Energy – A Smarter Way to Buy Energy -](https://goodenergy.com)**
>
> Commercial & Industrial We optimize your energy-buying strategy, so your business can operate more efficiently. Massachusetts Aggregation Program Find out the latest program benefits and how Massachusetts is leading the way. Community Energy...

> **[oddenergy.com is almost here!](http://www.oddenergy.com/)**
>
> The owner of this domain has not yet uploaded their website.

---

<div class="post-metadata">

**Author:** ![Yesh1923](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yesh1923](https://community.f5.com/u/Yesh1923)\
**Post date:** [January 18, 2023, 7:51am UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/7 "2023-01-18T07:51:18Z")

</div>

hi nimbos

how to merge these http\_request , could you please help

when HTTP\_REQUEST {  
if {([HTTP::header values “True-Client-IP”] equals “203.82.36.24”) or ([HTTP::header values “True-Client-IP”] equals “11.50.154.146”)  
or ([HTTP::header values “True-Client-IP”] equals “180.91.158.114”) or ([HTTP::header values “True-Client-IP”] equals “180.131.18.113”)  
or ([HTTP::header values “True-Client-IP”] equals “103.11.158.98”) or ([HTTP::header values “True-Client-IP”] equals “11.54.23.2”) or ([HTTP::header values “True-Client-IP”] equals “91.218.114.26”) or  
([HTTP::header values “True-Client-IP”] equals “91.28.11.4”) or ([HTTP::header values “True-Client-IP”] equals “92.63.8.47”) or  
}{  
HTTP::respond 400 content “site currently unavailable, Please try again later”  
}  
}

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

when HTTP\_REQUEST {  
if { [string tolower [HTTP::host]] equals “[energy.com](http://energy.com)” } {  
HTTP::respond 301 Location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” “Connection” “Close”  
return  
}  
elseif { [string tolower [HTTP::host]] equals “[ndtv.com](http://ndtv.com)” } {  
HTTP::respond 301 Location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” “Connection” “Close”  
return  
}  
elseif { [string tolower [HTTP::host]] equals “[corporate.ndtv.com](http://corporate.ndtv.com)” } {  
HTTP::respond 301 Location “[https://www.ndtv.co](https://www.ndtv.co)” “Connection” “Close”  
return

}  
}

---

<div class="post-metadata">

**Author:** ![Yesh1923](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yesh1923](https://community.f5.com/u/Yesh1923)\
**Post date:** [January 18, 2023, 7:52am UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/8 "2023-01-18T07:52:18Z")

</div>

or can we have two working irule ,one for http\_request another irule for block external ips

---

<div class="post-metadata">

**Author:** ![Hooni\_L](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@Hooni\_L](https://community.f5.com/u/Hooni_L)\
**Post date:** [January 19, 2023, 4:32am UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/9 "2023-01-19T04:32:18Z")

</div>

@Yesh1923

I think use date-group list and ‘IF’ on irule.

I couldn’t test it, but I checked that it was set up in the equipment.

refer below irule and datagroup list:

 ![스크린샷 2023-01-19 오후 1.31.24.png](https://d20hrnpixdzcsd.cloudfront.net/original/2X/2/2aa51196ce57671c2b90d1751076af8aed12d878.png)

 ![스크린샷 2023-01-19 오후 1.31.17.png](https://d20hrnpixdzcsd.cloudfront.net/original/3X/1/1/115511fe85a1c4af98c5771e7ea4a7280403d97a.png)

```tcl
when HTTP_REQUEST {
    if { [class match [HTTP::header values "True-Client-IP"] eq dg-client-ip] } {
        HTTP::respond 400 content "site currently unavailable, Please try again later"
    } elseif { [class match [HTTP::host] eq dg-domain] } {
        HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
        return
    }
}

```

---

<div class="post-metadata">

**Author:** ![Yesh1923](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yesh1923](https://community.f5.com/u/Yesh1923)\
**Post date:** [January 20, 2023, 2:47pm UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/10 "2023-01-20T14:47:32Z")

</div>

i add below but its not working as expected , web page not loading

when HTTP\_REQUEST {  
if { [class match [HTTP::header values “True-Client-IP”] eq mo-client-ip] } {  
HTTP::respond 400 content “site currently unavailable, Please try again later”  
} elseif { [class match [HTTP::host] eq mo-domain] } {  
HTTP::respond 301 Location “[[https://www](https://www).[HTTP::host][HTTP::uri](https://www.%5BHTTP::host%5D%5BHTTP::uri)]” “Connection” “Close”  
return  
}  
}

![iyyappan321_0-1674225977444.png](https://d20hrnpixdzcsd.cloudfront.net/original/3X/3/2/32384764666d0a66b5614c59b46af4da3a209ee9.png)

---

<div class="post-metadata">

**Author:** ![Hooni\_L](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@Hooni\_L](https://community.f5.com/u/Hooni_L)\
**Post date:** [January 26, 2023, 12:54am UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/11 "2023-01-26T00:54:45Z")

</div>

@Yesh1923

Hi

I’m on vacation, so I’m sorry for the late reply.

Can you check the ltm log message when after http requset?

thanks

---

<div class="post-metadata">

**Author:** ![Yesh1923](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yesh1923](https://community.f5.com/u/Yesh1923)\
**Post date:** [January 31, 2023, 10:16am UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/12 "2023-01-31T10:16:25Z")

</div>

how to merge these 2 irule in single irule

when HTTP\_REQUEST {

if { ([string tolower [HTTP::host]] equals “[essar.com](http://essar.com)”) && (([string tolower [HTTP::path]] eq “/en”)

or ([string tolower [HTTP::path]] eq “/en/”)) }

{

HTTP::respond 301 location “[https://essar.com/en-gb/](https://essar.com/en-gb/)”

elseif { ([string tolower [HTTP::host]] equals “[essar.com](http://essar.com)”) && ([string tolower [HTTP::path]] contains “/wholesale-fuels”) }

{

HTTP::respond 301 location “[https://www.essar.com/wholesale-fuels](https://www.essar.com/wholesale-fuels)” “Connection” “Close”

}

\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>

when HTTP\_REQUEST {

HTTP::respond 301 “Location” “https://[getfield [HTTP::host] “:” 1][HTTP::uri]” TCP::close

}

---

<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:** [January 31, 2023, 7:23pm UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/13 "2023-01-31T19:23:39Z")

</div>

Hi iyyappan321,

```tcl
when HTTP_REQUEST {
	if { ([string tolower [HTTP::host]] equals "essar.com") && (([string tolower [HTTP::path]] eq "/en") or ([string tolower [HTTP::path]] eq "/en/")) } {
		HTTP::respond 301 Location "https://essar.com/en-gb/"
		return
	} elseif { ([string tolower [HTTP::host]] equals "essar.com") && ([string tolower [HTTP::path]] contains "/wholesale-fuels") } {
		HTTP::respond 301 Location "https://www.essar.com/wholesale-fuels" "Connection" "Close"
		return
	}
	else {
		HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
		TCP::close
	}
}

```

You need to use this iRule in non 443 virtual server. Otherwise, redirect loop occurs.

---

<div class="post-metadata">

**Author:** ![Yesh1923](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yesh1923](https://community.f5.com/u/Yesh1923)\
**Post date:** [February 1, 2023, 8:23am UTC](https://community.f5.com/t/multiple-http-request-irules-not-working-same-virtual-server/71431/14 "2023-02-01T08:23:10Z")

</div>

hi enes thanks for your response

i used below rule , but i can able to access only - [energy.com](http://energy.com) site , if i access [essar.com](http://essar.com) its not getting redirect to&nbsp;“[https://corporate.essar.com/fr-fr](https://corporate.essar.com/fr-fr)”

my requirement is i want to access both - [energy.com](http://energy.com) , if i access&nbsp; [essar.com](http://essar.com) -- have to redirect to&nbsp;“[https://corporate.essar.com/fr-fr](https://corporate.essar.com/fr-fr)”

please help

when HTTP\_REQUEST {

if { ([string tolower [HTTP::host]] equals “[essar.co.uk](http://essar.co.uk)”) && (([string tolower [HTTP::path]] eq “/en”) or ([string tolower [HTTP::path]] eq “/en/”)) } {  
HTTP::respond 301 location “[https://wholesalefuels.essar.co.uk/en-gb/](https://wholesalefuels.essar.co.uk/en-gb/)”  
}

elseif { ([string tolower [HTTP::host]] equals “[energy.com](http://energy.com)”) } {  
HTTP::respond 301 location “[https://www.energy.com](https://www.energy.com)” Connection Close  
}  
elseif { ([string tolower [HTTP::host]] equals “[essar.com](http://essar.com)”) && ([string tolower [HTTP::path]] contains “fr-fr/wholesale-fuels”) } {  
HTTP::respond 301 location “[https://www.essar.com/fr-FR/wholesale-fuels](https://www.essar.com/fr-FR/wholesale-fuels)”  
}  
elseif { ([string tolower [HTTP::host]] equals “[www.essar.com](http://www.essar.com)”) && ([HTTP::path] eq “/”) } {  
HTTP::respond 301 location “[https://corporate.essar.com/fr-fr](https://corporate.essar.com/fr-fr)”  
}  
      else  {  
HTTP::respond 301 “Location” “https://[getfield [HTTP::host] “:” 1][HTTP::uri]”  
}
