# Header replacement assistance

**URL:** <https://community.f5.com/t/header-replacement-assistance/21281>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [October 24, 2009, 5:05pm UTC](https://community.f5.com/t/header-replacement-assistance/21281 "2009-10-24T17:05:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Bultman](https://avatars.discourse-cdn.com/v4/letter/n/e99b99/32.png) [@Nathan\_Bultman](https://community.f5.com/u/Nathan_Bultman)\
**Post date:** [October 24, 2009, 5:05pm UTC](https://community.f5.com/t/header-replacement-assistance/21281/1 "2009-10-24T17:05:48Z")

</div>

Problem:

When a request comes in, if it has the header MyHeader (regardless of value), we need to change the Referer header value, from [http://domain.com/path/object](http://domain.com/path/object) to [https://domain.com/path/object](https://domain.com/path/object)

I’ve tried to accomplish this with:

when HTTP\_REQUEST {

if {[HTTP::header exists “MyHeader”]} {

HTTP::header replace Referer [[https://domain.com](https://domain.com)[HTTP::uri] ]

}

}

Then sending a request:

GET /index.html HTTP/1.1

host: 1.1.1.1

MyHeader: foo

Referer: [http://domain.com](http://domain.com)

But I’m seeing the same referer header on the request when it egresses the LTM.

I’m a relative noob on iRules, so this might be something simple. Am I using ‘Exists’ correctly?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [October 25, 2009, 5:43pm UTC](https://community.f5.com/t/header-replacement-assistance/21281/2 "2009-10-25T17:43:43Z")

</div>

Hi Nathan,

I think you should find a TCL error in /var/log/ltm from trying to execute the value of [[https://domain.com](https://domain.com)[HTTP::uri](https://domain.com%5BHTTP::uri)] with the square braces that is wrapped in.

Can you clarify what you actually want to do in the Referer header update. Do you just want to replace http:// with https:// and preserve the rest of the header value? Your current rule is replacing the original Referer value with https:// and the current URI. The current URI wouldn’t typically be the same as the Referer URI.

Maybe try this:

```tcl
when HTTP_REQUEST { 
  
    log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri]\ 
       with Referer [HTTP::header Referer]" 
  
    if {[HTTP::header exists "MyHeader"]} {  
       log local0. "[IP::client_addr]:[TCP::client_port]: Updating Referer to\ 
          [string map -nocase {http:// https://} [HTTP::header Referer]" 
       HTTP::header replace Referer "[string map -nocase {http:// https://} [HTTP::header Referer]" 
    } 
 } 
 when HTTP_REQUEST priority 501 { 
    log local0. "[IP::client_addr]:[TCP::client_port] (501): Current Referer [HTTP::header Referer]" 
 }

```

Aaron
