# REDIRECTION ISSUE

**URL:** <https://community.f5.com/t/redirection-issue/35601>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [March 15, 2007, 8:09am UTC](https://community.f5.com/t/redirection-issue/35601 "2007-03-15T08:09:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonasD\_46068](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@JonasD\_46068](https://community.f5.com/u/JonasD_46068)\
**Post date:** [March 15, 2007, 8:09am UTC](https://community.f5.com/t/redirection-issue/35601/1 "2007-03-15T08:09:30Z")

</div>

I got the following iRule from someone in this forum:

when HTTP\_REQUEST {

set userhost [HTTP::host]

if { $userhost == “[testdomain.org](http://testdomain.org)”} {

set userhost “www.[HTTP::host]”

}

HTTP::redirect https://$userhost[HTTP::uri] }

It works GREAT. My issue now is I need to be able to add [subdomain.testdomain.org](http://subdomain.testdomain.org), [testdomain.net](http://testdomain.net), etc. Creating a 2nd rule doesn’t help. I tried combining them and separating them with an ‘or’ but got errors. I tried downloading the iRule editor but the download link seems to just loop back to where you start. I need this rule because the SSL cert on the F5 is only for [www.testdomain.com](http://www.testdomain.com) and the rule prevents the cert error that makes end-user think there’s some issue. Please help, I’m an iRule idiot.

Jhd

---

<div class="post-metadata">

**Author:** ![JonasD\_46068](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@JonasD\_46068](https://community.f5.com/u/JonasD_46068)\
**Post date:** [March 15, 2007, 8:32am UTC](https://community.f5.com/t/redirection-issue/35601/2 "2007-03-15T08:32:47Z")

</div>

I tried to use an elseif to add the [subdomain.testdomain.com](http://subdomain.testdomain.com) and it is appending [www.subdomain.testdomain.com](http://www.subdomain.testdomain.com) which does NOT exist. So I am close but no cigar. I see ‘why’ it did it but I"m not sure how to fix. Here’s what I tried that didn’t quite work:

when HTTP\_REQUEST {

set userhost [HTTP::host]

if { $userhost == “[testdomain.org](http://testdomain.org)”} {

set userhost “www.[HTTP::host]”

}

elseif { $userhost == “[ml.testdomain.org](http://ml.testdomain.org)”} {

set userhost “www.[HTTP::host]”

}

HTTP::redirect https://$userhost[HTTP::uri] }

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [March 30, 2007, 5:15pm UTC](https://community.f5.com/t/redirection-issue/35601/3 "2007-03-30T17:15:39Z")

</div>

I think what you’re looking for is something like:

```tcl
when HTTP_REQUEST {
  set userhost [HTTP::host]
  if { $userhost equals "testdomain.org"} {
    set userhost "www.[HTTP::host]"
  } elseif { $userhost equals "ml.testdomain.org"} {
    set userhost "[HTTP::host]"
  } elseif { $userhost equals "testdomain.net"} {
    set userhost "www.[HTTP::host]"
  }
  HTTP::redirect "https://$userhost[HTTP::uri]"
}

```

Note that the way you’re manipulating userhost changes depending on what it was set to coming from the client. If you see [subdomain.testdomain.org](http://subdomain.testdomain.org), you’re not going to want to prepend a www to it. If you see just [testdomain.org](http://testdomain.org) or [testdomain.net](http://testdomain.net), then you will.

Make sense?

Colin

---

<div class="post-metadata">

**Author:** ![Parveez\_70209](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Parveez\_70209](https://community.f5.com/u/Parveez_70209)\
**Post date:** [August 12, 2014, 9:07pm UTC](https://community.f5.com/t/redirection-issue/35601/4 "2014-08-12T21:07:58Z")

</div>

Hi Colin,

Here is the detailed issue:

We have HTTP plus HTTPS Virtual-Server, where anyone who will hit:: [http://shop.test.com/broutlet](http://shop.test.com/broutlet) or [http://shop.test.com/broutlet/\](http://shop.test.com/broutlet/%5C)\* , it should redirect to [http://outlet.lenovo.com/broutlet/br/pt/](http://outlet.lenovo.com/broutlet/br/pt/) to be accurate.

Where /\* can be anything, for now only [http://shop.test.com/broutlet/](http://shop.test.com/broutlet/) redirection is happening to [http://outlet.lenovo.com/broutlet/br/pt/](http://outlet.lenovo.com/broutlet/br/pt/) but not with [http://shop.test.com/broutlet/\](http://shop.test.com/broutlet/%5C)\*(just one for example : [http://shop.test.com/broutlet/br/pt](http://shop.test.com/broutlet/br/pt))

Regards PZ

---

<div class="post-metadata">

**Author:** ![Parveez\_70209](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Parveez\_70209](https://community.f5.com/u/Parveez_70209)\
**Post date:** [August 14, 2014, 6:28pm UTC](https://community.f5.com/t/redirection-issue/35601/5 "2014-08-14T18:28:57Z")

</div>

Hi Team,

The below Irule is working good, sorry for the confusion:

when HTTP\_REQUEST {

if { [string tolower [HTTP::uri]] starts\_with “/broutlet” } { HTTP::redirect “[http://olet.domain.com/broutlet/br/pt/](http://olet.domain.com/broutlet/br/pt/)” } }

But this is giving 302 redirection, it should give 301 redirection, how my Irule will look like.

Thanks and Regards Parveez

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [August 16, 2014, 11:04pm UTC](https://community.f5.com/t/redirection-issue/35601/6 "2014-08-16T23:04:11Z")

</div>

But this is giving 302 redirection, it should give 301 redirection, how my Irule will look like.

you have to use HTTP::respond instead of HTTP::redirect.

HTTP::respond

> **[DevCentral](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.
