# data gets lost when URL redirect

**URL:** <https://community.f5.com/t/data-gets-lost-when-url-redirect/48665>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [November 12, 2007, 12:15pm UTC](https://community.f5.com/t/data-gets-lost-when-url-redirect/48665 "2007-11-12T12:15:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheManu](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@TheManu](https://community.f5.com/u/TheManu)\
**Post date:** [November 12, 2007, 12:15pm UTC](https://community.f5.com/t/data-gets-lost-when-url-redirect/48665/1 "2007-11-12T12:15:47Z")

</div>

I want to implement a URL redirect for the following URL:

[https://test.company.com/branch/workinggroup](https://test.company.com/branch/workinggroup)

Destination is:

[https://test.company.com/programs/logic.php](https://test.company.com/programs/logic.php)

The purpose of this page is that a user may post XML data, which is put into the body of the page. The PHP file contains the logic to read this data and automatically create an order in our system.

When I use the following URL redirection, the request is the redirected but the data gets lost:

when HTTP\_REQUEST { if { [HTTP::host] eq “[test.company.com/branch/workinggroup](http://test.company.com/branch/workinggroup)”}{ HTTP::header replace “host” “[test.company.com/programs/logic.php](http://test.company.com/programs/logic.php)”}}

Does anyone know how to change the iRule to keep the order process working?

Thanks for your help.

---

<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:** [November 12, 2007, 12:32pm UTC](https://community.f5.com/t/data-gets-lost-when-url-redirect/48665/2 "2007-11-12T12:32:14Z")

</div>

Hi,

The Host header value doesn’t include the URI, so that rule should never get triggered to replace the Host header. Also, to be exact, you want to rewrite the host and URI--not send a 302 redirect. The redirect would result in the client sending a new GET request to the redirect location.

Can you try this?

```tcl
when HTTP_REQUEST {
   if { [HTTP::host] eq "test.company.com"}{
      log local0. "Rewriting client request for host: [HTTP::header value Host], for URI: [HTTP::uri]"
      HTTP::header replace "host" "test.company.com"
      HTTP::uri "/programs/logic.php"
   }
}

```

The log statement will be written to /var/log/ltm. You can watch the log using ‘tail -f /var/log/ltm’.

Aaron

---

<div class="post-metadata">

**Author:** ![TheManu](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@TheManu](https://community.f5.com/u/TheManu)\
**Post date:** [November 12, 2007, 12:46pm UTC](https://community.f5.com/t/data-gets-lost-when-url-redirect/48665/3 "2007-11-12T12:46:21Z")

</div>

Thank you for reply.

If i use this:

```tcl
when HTTP_REQUEST {
   if { [HTTP::host] eq "test.company.com"}{
      log local0. "Rewriting client request for host: [HTTP::header value Host], for URI: [HTTP::uri]"
      HTTP::header replace "host" "test.company.com"
      HTTP::uri "/programs/logic.php"
   }
}

```

the redirection will allways target the logic.php.

May I use it like this?

```tcl
when HTTP_REQUEST {
   if { [HTTP::host] eq "test.company.com/branch1/workinggroup"}{
      log local0. "Rewriting client request for host: [HTTP::header value Host], for URI: [HTTP::uri]"
      HTTP::header replace "host" "test.company.com"
      HTTP::uri "/programs/logic1.php"
   }
}

```

```tcl
when HTTP_REQUEST {
   if { [HTTP::host] eq "test.company.com/branch2/workinggroup"}{
      log local0. "Rewriting client request for host: [HTTP::header value Host], for URI: [HTTP::uri]"
      HTTP::header replace "host" "test.company.com"
      HTTP::uri "/programs/logic2.php"
   }
}

```

---

<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:** [November 12, 2007, 1:47pm UTC](https://community.f5.com/t/data-gets-lost-when-url-redirect/48665/4 "2007-11-12T13:47:46Z")

</div>

Do you actually expect Host header values other than [test.company.com](http://test.company.com)? Assuming not, you could try this to verify the URI matches for the rewrite:

```tcl
when HTTP_REQUEST {
    check if the path of the request starts with "/branch1/workinggroup"
   if {[HTTP::path] starts_with "/branch1/workinggroup"}{
      HTTP::header replace "Host" "test.company.com"
      HTTP::uri "/programs/logic1.php"
    check if the path of the request starts with "/branch2/workinggroup"
   } elseif }{[HTTP::path] starts_with "/branch2/workinggroup"}{
      HTTP::header replace "Host" "test.company.com"
      HTTP::uri "/programs/logic2.php"
   }
}

```

If you do want to validate the Host header equals “[test.company.com](http://test.company.com)” you could wrap the path checks in an ‘if’.

Aaron

---

<div class="post-metadata">

**Author:** ![TheManu](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@TheManu](https://community.f5.com/u/TheManu)\
**Post date:** [November 12, 2007, 2:13pm UTC](https://community.f5.com/t/data-gets-lost-when-url-redirect/48665/5 "2007-11-12T14:13:01Z")

</div>

Hi Aaron,

I can’t use the Code you have just posted because I get an error:

01070151:3: Rule [iRule1] error:

line 1: [wrong args] [when HTTP\_REQUEST]

line 2: [undefined procedure:

---

<div class="post-metadata">

**Author:** ![TheManu](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@TheManu](https://community.f5.com/u/TheManu)\
**Post date:** [November 12, 2007, 2:20pm UTC](https://community.f5.com/t/data-gets-lost-when-url-redirect/48665/6 "2007-11-12T14:20:17Z")

</div>

Me again,

i’ve found the error in my code…

…the problem was a line break which the system didn’t like

Thank you very much…System is working now!!!
