# rewrite issue

**URL:** <https://community.f5.com/t/rewrite-issue/40475>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [June 14, 2007, 3:12pm UTC](https://community.f5.com/t/rewrite-issue/40475 "2007-06-14T15:12:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Haggerty](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Justin\_Haggerty](https://community.f5.com/u/Justin_Haggerty)\
**Post date:** [June 14, 2007, 3:12pm UTC](https://community.f5.com/t/rewrite-issue/40475/1 "2007-06-14T15:12:44Z")

</div>

Say our app behind our bigip answers up to [www.xyz.com](http://www.xyz.com) from the web. the server behind the bigip’s hostname is actually [www.abc.com](http://www.abc.com). My current setup is working except for instances when people browse to say [www.xyz.com/admin/](http://www.xyz.com/admin/) there browser then tries to load [www.abc.com/admin/index.html](http://www.abc.com/admin/index.html). This eventually times out as [www.abc.com](http://www.abc.com) isn’t open to the world. What I’m looking to do is get that redirect to go to [www.xyz.com/admin/index.html](http://www.xyz.com/admin/index.html).

I wrote the following irule, but it doesn’t seem to be working. They still get sent to [abc.com](http://abc.com).

```tcl
when HTTP_REQUEST {
  if { [HTTP::host] contains "abc.com" } {
    HTTP::redirect "https://www.xyz.com/[HTTP::uri]"
  }
}

```

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Deb\_Allen\_18](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Deb\_Allen\_18](https://community.f5.com/u/Deb_Allen_18)\
**Post date:** [June 14, 2007, 5:22pm UTC](https://community.f5.com/t/rewrite-issue/40475/2 "2007-06-14T17:22:37Z")

</div>

(moved your post to the proper forum)

Your iRule looks fine.

Not sure what you mean when you say users “browse to [.xyz Domain Names | Join Generation XYZ](http://www.xyz.com/admin/)… (but) browser then tries to load [www.abc.com/admin/index.html](http://www.abc.com/admin/index.html)”. If the [abc.com](http://abc.com) URI is showing up in the browser, there must be a server-originated redirect or something else going on between the user requesting the [xyz.com](http://xyz.com) URI and the failed request to [abc.com](http://abc.com).

I see you are redirecting to HTTPS. If the original request is also HTTPS, you must decrypt the traffic with a clientssl profile before you can read the host header to determine if a redirect is in order.

HTH

/deb

---

<div class="post-metadata">

**Author:** ![Justin\_Haggerty](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Justin\_Haggerty](https://community.f5.com/u/Justin_Haggerty)\
**Post date:** [June 17, 2007, 3:28pm UTC](https://community.f5.com/t/rewrite-issue/40475/3 "2007-06-17T15:28:18Z")

</div>

the problem i’m seeing is when some one doesn’t specify the actual file name. like /admin instead of /admin/index.html. apache knows to look for index.html in the directory and redirect to that page. But it is redirecting to the wrong hostname. They’re getting sent to [abc.com/admin/index.html](http://abc.com/admin/index.html), they requested [.xyz Domain Names | Join Generation XYZ](http://xyz.com/admin/).

I’m guessing we could set the apache config to use the hostname [xyz.com](http://xyz.com), but the customer was wondering if the f5 could fix this instead.

as for ssl, that was a typo. it should have just said http in the irule.

---

<div class="post-metadata">

**Author:** ![Joe\_Pruitt](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/joe_pruitt/32/8438_2.png) [@Joe\_Pruitt](https://community.f5.com/u/Joe_Pruitt)\
**Post date:** [June 18, 2007, 4:22pm UTC](https://community.f5.com/t/rewrite-issue/40475/4 "2007-06-18T16:22:58Z")

</div>

What’s happening is that the backend webserver is sending a 301 or 302 based redirect to the browser. The redirect is in the HTTP response header named Location. For your situation, all you’ll need to do is catch 301 or 302 responses in the Response and replace [abc.com](http://abc.com) with [xyz.com](http://xyz.com) in the response value. Something like this should work for you.

```tcl
when HTTP_RESPONSE {
  switch [HTTP::status] {
    301 -
    302 {
      HTTP::header Location [string map {abc.com xyz.com} [HTTP::header Location]]
    }
  }
}

```

Basically this iRule will look in the response for all 301 and 302 status codes and if one is found, then set the Location header to the old location header with the strings “[abc.com](http://abc.com)” replaced with “[xyz.com](http://xyz.com)”.

-Joe
