# redirection loop

**URL:** <https://community.f5.com/t/redirection-loop/35949>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [August 8, 2012, 2:21am UTC](https://community.f5.com/t/redirection-loop/35949 "2012-08-08T02:21:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![f5\_user\_7996](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@f5\_user\_7996](https://community.f5.com/u/f5_user_7996)\
**Post date:** [August 8, 2012, 2:21am UTC](https://community.f5.com/t/redirection-loop/35949/1 "2012-08-08T02:21:40Z")

</div>

Hi all,

Anybody could help me on this scenario

A customer wants to redirect their website with 301 response with the following scenarios.

1) customer.co.nz → [http://www.customer.co.nz/Pages/default.aspx](http://www.customer.co.nz/Pages/default.aspx)

2) [www.customer.co.nz](http://www.customer.co.nz) → [http://www.customer.co.nz/Pages/default.aspx](http://www.customer.co.nz/Pages/default.aspx)

I was able to sort the first one with this irule:

when HTTP\_REQUEST {

if { [string tolower [HTTP::]] equals “customer.co.nz” } {

HTTP::respond 301 location [http://www.customer.co.nz/Pages/Default.aspx](http://www.customer.co.nz/Pages/Default.aspx)

}

}

But on the second one when I apply the rule below it says on my browser “redirection loop”

when HTTP\_REQUEST {

if { [string tolower [HTTP::]] equals “[www.customer.co.nz](http://www.customer.co.nz)” } {

HTTP::respond 301 location [http://www.customer.co.nz/Pages](http://www.customer.co.nz/Pages)/default.aspx"

}

}

I’m not sure what’s wrong with the second rule, they are separate irule and both mounted on one virtual server.

Thanks.

---

<div class="post-metadata">

**Author:** ![Gbps\_31870](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gbps\_31870](https://community.f5.com/u/Gbps_31870)\
**Post date:** [August 8, 2012, 6:45am UTC](https://community.f5.com/t/redirection-loop/35949/2 "2012-08-08T06:45:56Z")

</div>

Hi,

Try This iRule, it should works with both scenarios.

when HTTP\_REQUEST

if {([string tolower [HTTP::host]] contains “customer.co.nz”) and ([HTTP::path] equals “/”)} {

HTTP::respond 301 location [http://www.customer.co.nz/Pages/default.aspx](http://www.customer.co.nz/Pages/default.aspx)

}

or instead of HTTP::respond 301 … you can type HTTP::redirect “[http://www.customer.co.nz/Pages/default.aspx](http://www.customer.co.nz/Pages/default.aspx)” but this redirection will be 302 response instead.

HTH

BR,

Abdul

---

<div class="post-metadata">

**Author:** ![f5\_user\_7996](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@f5\_user\_7996](https://community.f5.com/u/f5_user_7996)\
**Post date:** [August 9, 2012, 2:50am UTC](https://community.f5.com/t/redirection-loop/35949/3 "2012-08-09T02:50:46Z")

</div>

Hi Abdul,

The rule doesn’t work it’s giving me the error below:

01070151:3: Rule [Trial\_irule] error: line 1: [wrong args] [when HTTP\_REQUEST] line 2: [command is not valid in the current scope] [if {([string tolower [HTTP::host]] contains “customer.co.nz”) and ([HTTP::path] equals “/”)} { HTTP::respond 301 location [http://www.customer.co.nz/Pages/default.aspx](http://www.customer.co.nz/Pages/default.aspx) }]

---

<div class="post-metadata">

**Author:** ![Gbps\_31870](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gbps\_31870](https://community.f5.com/u/Gbps_31870)\
**Post date:** [August 9, 2012, 3:34am UTC](https://community.f5.com/t/redirection-loop/35949/4 "2012-08-09T03:34:24Z")

</div>

Hi F5\_user,

Sorry for that, just add one open bracket { after HTTP\_REQUEST, and a close bracket } at the end of the iRule.

---

<div class="post-metadata">

**Author:** ![avi123\_184259](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@avi123\_184259](https://community.f5.com/u/avi123_184259)\
**Post date:** [September 11, 2015, 11:02pm UTC](https://community.f5.com/t/redirection-loop/35949/5 "2015-09-11T23:02:05Z")

</div>

Hi Abdul,

I tried same, but still getting into redirect loop. when HTTP\_REQUEST { if {([string tolower [HTTP::host]] contains “[www.test.com](http://www.test.com)”) and ([HTTP::path] equals “/”)} { HTTP::respond 301 location “[http://www.test.com/en-us](http://www.test.com/en-us)” } }

---

<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:** [September 14, 2015, 12:51pm UTC](https://community.f5.com/t/redirection-loop/35949/6 "2015-09-14T12:51:56Z")

</div>

Hi avi123,

in

```tcl
http://www.test.com/en-us

```

path is

```tcl
/

```

```tcl
en-us

```

is a fragment identifier and is not part of path

are you sure the fragment is sent to the F5? look [this thread](https://devcentral.f5.com/questions/irule-use-of-httpuri-leaves-off-url-fragment-how-to-capture-that-information) for more info.

---

<div class="post-metadata">

**Author:** ![avi123\_184259](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@avi123\_184259](https://community.f5.com/u/avi123_184259)\
**Post date:** [October 8, 2015, 2:59pm UTC](https://community.f5.com/t/redirection-loop/35949/7 "2015-10-08T14:59:32Z")

</div>

Hi Stanislas,

Yeah, you are right, en-us is not being sent to F5, which is causing the loop.

Thank you so much for pointing to that.
