# HTTP::header replace problem

**URL:** <https://community.f5.com/t/http-header-replace-problem/27843>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [July 31, 2013, 10:09am UTC](https://community.f5.com/t/http-header-replace-problem/27843 "2013-07-31T10:09:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![LyonsG\_85618](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@LyonsG\_85618](https://community.f5.com/u/LyonsG_85618)\
**Post date:** [July 31, 2013, 10:09am UTC](https://community.f5.com/t/http-header-replace-problem/27843/1 "2013-07-31T10:09:44Z")

</div>

Hi folks.

I have a simple iRule to replace a host & uri

_when HTTP\_REQUEST {_

_set requestedHost [string tolower [HTTP::host]]_

_set requestedURI [HTTP::uri]_

_if {($requestedHost equals “[test1.domain.com](http://test1.domain.com)”) and ($requestedURI equals “/”)} {_

_HTTP::header replace Host “[test2.domain.com](http://test2.domain.com)”_

_HTTP::uri “/some/other/uri”_

_}_

_}_

This iRule work like a charm on my HTTP virtual server. However when I assign it to the HTTPS virtual server I get the following error:

- Operation not supported (line 4) invoked from within “HTTP::header replace Host “[test2.domain.com](http://test2.domain.com)””

There are other irules on the virtual server that control routing to pools based on various external class files however I am not sure how they woluld be causing the issue I am seeing /

The same irules are assigned to both HTTP & HTTPS virtual servers.

Any ideas?

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [July 31, 2013, 1:07pm UTC](https://community.f5.com/t/http-header-replace-problem/27843/2 "2013-07-31T13:07:11Z")

</div>

can you post the https virtual server configuration?

e.g.

tmsh list ltm virtual (name)

---

<div class="post-metadata">

**Author:** ![LyonsG\_85618](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@LyonsG\_85618](https://community.f5.com/u/LyonsG_85618)\
**Post date:** [July 31, 2013, 1:27pm UTC](https://community.f5.com/t/http-header-replace-problem/27843/3 "2013-07-31T13:27:07Z")

</div>

ltm virtual VS\_S1P\_PD03\_EXTERNAL\_LIVE\_HTTPS {

destination 172.31.137.59:https

ip-protocol tcp

mask 255.255.255.255

partition S1PEL

profiles {

PROFILE\_S1P\_PD03\_EXTERNAL\_LIVE\_CLIENTSSL {

context clientside

}

PROFILE\_S1P\_PD03\_EXTERNAL\_LIVE\_HTTP { }

PROFILE\_S1P\_PD03\_EXTERNAL\_LIVE\_SERVERSSL {

context serverside

}

oneconnect { }

tcp { }

}

rules {

IRULE\_COMMON\_LOG

IRULE\_S1P\_PD03\_EXTERNAL\_LIVE\_CIAMAINTENANCE

IRULE\_S1P\_PD03\_EXTERNAL\_LIVE\_ROUTING

IRULE\_S1P\_PD03\_EXTERNAL\_LIVE\_EZONE

}

snat automap

}

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [July 31, 2013, 2:39pm UTC](https://community.f5.com/t/http-header-replace-problem/27843/4 "2013-07-31T14:39:18Z")

</div>

the configuration and irule look okay to me. is this only virtual server the irule is applied?

---

<div class="post-metadata">

**Author:** ![LyonsG\_85618](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@LyonsG\_85618](https://community.f5.com/u/LyonsG_85618)\
**Post date:** [August 1, 2013, 7:28am UTC](https://community.f5.com/t/http-header-replace-problem/27843/5 "2013-08-01T07:28:22Z")

</div>

Hi Nitass

I do have the irule assigned to an HTTP virtual server and it works fine.

ltm virtual VS\_S1P\_PD03\_EXTERNAL\_LIVE\_HTTP {

destination 172.31.137.59:http

ip-protocol tcp

mask 255.255.255.255

partition S1PEL

profiles {

PROFILE\_S1P\_PD03\_EXTERNAL\_LIVE\_HTTP { }

oneconnect { }

tcp { }

}

rules {

IRULE\_COMMON\_LOG

IRULE\_S1P\_PD03\_EXTERNAL\_LIVE\_EZONE

IRULE\_S1P\_PD03\_EXTERNAL\_LIVE\_CIAMAINTENANCE

IRULE\_S1P\_PD03\_EXTERNAL\_LIVE\_ROUTING

}

snat automap

}

I think this is why I am finding it strange it doesnt work on HTTPS.

I will try removing sonme of the other irules in case they are causing the issue.

Unfortunately though the ROUTING irule does control everything thing else so removing this will probably cause virtual server to fail anyway.

Thanks

---

<div class="post-metadata">

**Author:** ![LyonsG\_85618](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@LyonsG\_85618](https://community.f5.com/u/LyonsG_85618)\
**Post date:** [August 1, 2013, 7:34am UTC](https://community.f5.com/t/http-header-replace-problem/27843/6 "2013-08-01T07:34:16Z")

</div>

Update:

The irule now works on HTTPS.

I havent changed anything excepy for rebooting PC overnight.

It musy have been some browser issue (though I had been clearing cache/cookies etc).

Thanks for your help Nitass!

---

<div class="post-metadata">

**Author:** ![LyonsG\_85618](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@LyonsG\_85618](https://community.f5.com/u/LyonsG_85618)\
**Post date:** [August 9, 2013, 8:11am UTC](https://community.f5.com/t/http-header-replace-problem/27843/7 "2013-08-09T08:11:36Z")

</div>

Although iRule is now working fine on both HTTP and HTTP virtual servers I have found a slight issue.

When i stay on the same VIP the irule works fine

Example:

1) If uri is [http://www.test1.com](http://www.test1.com) and irule is set to replace host to [www.test2.com](http://www.test2.com) and change uri to /index.html - i get re-written and sent to correct page but browser still has [http://www.test1.com](http://www.test1.com) - This is good and is working as designed

2) if i try the same as 1) but replace protocol with https and change uri to /secure (i have another irule that picks up that /secure should be https and forces all traffic to HTTPS virtual server) this works as expected e.g. requested uri is [https://www.test1.com/secure](https://www.test1.com/secure) - gets re-written to [https://www.test2.com/secure](https://www.test2.com/secure) and browser retains [https://www.test1.com/secure](https://www.test1.com/secure)

However…

3) If i enter [http://www.test1.com/secure](http://www.test1.com/secure) - i get redirected to [https://www.test2.com/secure](https://www.test2.com/secure) and browser shows this in address bar.

I am guessing it is something to do with the other irules i have - but just wondered whether anyone had seen something like this previously?

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [August 9, 2013, 8:38am UTC](https://community.f5.com/t/http-header-replace-problem/27843/8 "2013-08-09T08:38:03Z")

</div>

I am guessing it is something to do with the other irules i have - but just wondered whether anyone had seen something like this previously? can you post the irule?

---

<div class="post-metadata">

**Author:** ![LyonsG\_85618](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@LyonsG\_85618](https://community.f5.com/u/LyonsG_85618)\
**Post date:** [August 9, 2013, 8:50am UTC](https://community.f5.com/t/http-header-replace-problem/27843/9 "2013-08-09T08:50:56Z")

</div>

I think this is the relevant part of irule

And looking at it now i guess it makes sense…the re-write from [http://www.test1.com](http://www.test1.com) to [https://www.test1.com/secure](https://www.test1.com/secure) is picked up by this irule that knows /secure is HTTPS so it then does a redirect

( HTTP::respond 301 noserver Location “https://$requestedHost$requestedURI”)

I’ll need to figure out how to prevent this happening (perhaps a check to see whether referer = [www.test1.com](http://www.test1.com)?)

REDIRECT HTTP to HTTPS

Check if URI is listed as requiring to be https and redirect is appropriate

} elseif {($protocol equals “HTTP”) and ([class match -value $requestedURI starts\_with $portalContextRoutingClass] equals “https”)} {

set codeBlock “REDIRECT HTTP to HTTPS”

if {$debug \>= 1} {

log local0. “$vsName : Debug Level $debug : $codeBlock : Redirecting to https://$requestedHost$requestedURI”

}

HTTP::respond 301 noserver Location “https://$requestedHost$requestedURI”

REDIRECT HTTP to HTTPS
