# iRule Question

**URL:** <https://community.f5.com/t/irule-question/13000>\
**Category:** Technical Forums\
**Tags:** irules, application-delivery\
**Created:** [October 13, 2017, 5:03pm UTC](https://community.f5.com/t/irule-question/13000 "2017-10-13T17:03:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krishna\_251070](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@Krishna\_251070](https://community.f5.com/u/Krishna_251070)\
**Post date:** [October 13, 2017, 5:03pm UTC](https://community.f5.com/t/irule-question/13000/1 "2017-10-13T17:03:11Z")

</div>

Hi Experts,

I have an iRule that looks like this which is applied to a Virtual Server that listens on port **8080**.

```tcl
when HTTP_REQUEST {
   HTTP::redirect http://[getfield [HTTP::host] ":" 1][HTTP::uri]

}

```

But for some reason this is not getting redirected to port 80 virtual server as I expected. Can anyone check why this is not working?

---

<div class="post-metadata">

**Author:** ![Kevin\_Davies](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_davies/32/1696_2.png) [@Kevin\_Davies](https://community.f5.com/u/Kevin_Davies)\
**Post date:** [October 13, 2017, 8:48pm UTC](https://community.f5.com/t/irule-question/13000/2 "2017-10-13T20:48:42Z")

</div>

Logging is your friend Krishna.

```tcl
when HTTP_REQUEST {
   HTTP::redirect http://[getfield [HTTP::host] ":" 1][HTTP::uri]
   log local0. "Redirected http://[getfield [HTTP::host] ":" 1][HTTP::uri]"
}

```

Then goto System → Logs and search for “redirected” to see what the redirects actually look like. This may give you a clue as to the problem.

---

<div class="post-metadata">

**Author:** ![JRahm](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/jrahm/32/3327_2.png) [@JRahm](https://community.f5.com/u/JRahm)\
**Post date:** [October 13, 2017, 9:20pm UTC](https://community.f5.com/t/irule-question/13000/3 "2017-10-13T21:20:56Z")

</div>

This works perfectly on my test system. Adding a log line as Kevin suggests:

```tcl
log local0. "Rewriting [HTTP::host] to [getfield [HTTP::host] ":" 1]"
 Result:
Oct 13 16:16:42 ltm3 info tmm[48128]: Rule /Common/redirectest : Rewriting 192.168.102.62:8080 to 192.168.102.62

```

From the tcp stream in my wireshark capture, you can see the Host with the 8080 port, the rewritten Location header without, and the subsequent request to port 80:

```tcl
GET / HTTP/1.1
Host: 192.168.102.62:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1

HTTP/1.0 302 Found
Location: http://192.168.102.62/
Server: BigIP
Connection: Keep-Alive
Content-Length: 0    

GET / HTTP/1.1
Host: 192.168.102.62
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1

```
