# iRule redirect syntax

**URL:** <https://community.f5.com/t/irule-redirect-syntax/20784>\
**Category:** Technical Forums\
**Tags:** irules, devops, ltm, application-delivery\
**Created:** [August 14, 2015, 3:45pm UTC](https://community.f5.com/t/irule-redirect-syntax/20784 "2015-08-14T15:45:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mystic\_142330](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mystic\_142330](https://community.f5.com/u/Mystic_142330)\
**Post date:** [August 14, 2015, 3:45pm UTC](https://community.f5.com/t/irule-redirect-syntax/20784/1 "2015-08-14T15:45:17Z")

</div>

Hello,

I’m trying to create a simple redirect irule for a VIP i created for port 8080. Obviously users are typing in the following

[http://mywebsite.com](http://mywebsite.com) and it’s failing as it needs to be [http://mywebsite.com:8080/imagecast/default.asp](http://mywebsite.com:8080/imagecast/default.asp)

I’ve tried the following iRule and I can get the VIP to redirect when i manually type in :8080. I would like this to redirect the user to the correct port and file extension:

when HTTP\_REQUEST { if { [HTTP::uri] equals “” or [HTTP::uri] equals “/” } { HTTP::redirect [http://mywebsite.com:8080/imagecast/default.asp](http://mywebsite.com:8080/imagecast/default.asp) }}

I’ve tried a few different things but doesn’t seem to be coming close.

---

<div class="post-metadata">

**Author:** ![stan\_piron](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stan\_piron](https://community.f5.com/u/stan_piron)\
**Post date:** [August 14, 2015, 3:49pm UTC](https://community.f5.com/t/irule-redirect-syntax/20784/2 "2015-08-14T15:49:09Z")

</div>

Hi,

did you create a VS on port 80?

on this VS create the following irule:

```tcl
when HTTP_REQUEST { 
    HTTP::redirect http://[HTTP::host]:8080[HTTP::uri] 
}

```

---

<div class="post-metadata">

**Author:** ![Mystic\_142330](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mystic\_142330](https://community.f5.com/u/Mystic_142330)\
**Post date:** [August 14, 2015, 3:58pm UTC](https://community.f5.com/t/irule-redirect-syntax/20784/3 "2015-08-14T15:58:38Z")

</div>

Awesome that worked. I actually did change the VS to port 80. When i did that still no dice so i re-wrote my iRule like this:

when HTTP\_REQUEST { if { [HTTP::uri] equals “” or [HTTP::uri] equals “/” } { HTTP::redirect [http://mywebsite.com/imagecast/default.asp](http://mywebsite.com/imagecast/default.asp) }}

I removed the 8080 and it works fine. Although your method looks like ti will work as well and i will test it. Thank you!!!

---

<div class="post-metadata">

**Author:** ![stan\_piron](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stan\_piron](https://community.f5.com/u/stan_piron)\
**Post date:** [August 14, 2015, 4:28pm UTC](https://community.f5.com/t/irule-redirect-syntax/20784/4 "2015-08-14T16:28:28Z")

</div>

Hi,

in your irule, remove the condition [HTTP::uri] equals “” .

an uri is never empty. when the user enter [http://mywebsite.com](http://mywebsite.com) in the browser, the request send is:

```tcl
GET / HTTP/1.1
Host: mywebsite.com
Other Headers...

```
