# https redirection

**URL:** <https://community.f5.com/t/https-redirection/50764>\
**Category:** Technical Forums\
**Tags:** irules, big-ip, devops, application-delivery\
**Created:** [September 7, 2016, 8:49pm UTC](https://community.f5.com/t/https-redirection/50764 "2016-09-07T20:49:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anush](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Anush](https://community.f5.com/u/Anush)\
**Post date:** [September 7, 2016, 8:49pm UTC](https://community.f5.com/t/https-redirection/50764/1 "2016-09-07T20:49:25Z")

</div>

Hi Experts,

Trying to figure out how this redirection can be configured.

[https://devcentral.com/groups/Research/\](https://devcentral.com/groups/Research/%5C)\* should get redirected to ""[https://F5.com/devresearch/\](https://F5.com/devresearch/%5C)\*

“\*” says whatever user type, it get populate same in redirection site

For example,

[https://devcentral.com/groups/Research/F5experts](https://devcentral.com/groups/Research/F5experts) get redirect to [https://F5.com/devresearch/F5experts](https://F5.com/devresearch/F5experts)

this looks tricky as it has both static and variable path in URI.

Thanks

---

<div class="post-metadata">

**Author:** ![Anush](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Anush](https://community.f5.com/u/Anush)\
**Post date:** [September 7, 2016, 9:25pm UTC](https://community.f5.com/t/https-redirection/50764/2 "2016-09-07T21:25:47Z")

</div>

how about this? looks ok?

```markup
when HTTP_REQUEST {
    log local0. "Incoming URI = [HTTP::uri]"
    if { [string tolower [HTTP::host]] equals "devcentral.com" && [string tolower [HTTP::uri]] starts_with "/groups/Research/" } {
        set uri [string map -nocase {"/groups/Research/" "/devresearch/"} [HTTP::uri]]
        log local0. "New URI = $uri"
        HTTP::redirect "https://f5.com[$uri]"
    }
}

```

---

<div class="post-metadata">

**Author:** ![Vijay\_E](https://avatars.discourse-cdn.com/v4/letter/v/4bbf92/32.png) [@Vijay\_E](https://community.f5.com/u/Vijay_E)\
**Post date:** [September 7, 2016, 9:28pm UTC](https://community.f5.com/t/https-redirection/50764/3 "2016-09-07T21:28:10Z")

</div>

This is a rough template. You may have to play around with the [getfield](https://devcentral.f5.com/wiki/iRules.getfield.ashx) command to achieve your requirements:

```markup
when HTTP_REQUEST {
if { ([HTTP::host] eq "devcentral.com") and ([HTTP::uri] starts_with "/groups/Research/") } {
HTTP::respond 301 Location "https://f5.com/devresearch[getfield [HTTP::uri] "/groups/Research" 2]"
}
}

```

---

<div class="post-metadata">

**Author:** ![Anush](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Anush](https://community.f5.com/u/Anush)\
**Post date:** [September 7, 2016, 9:49pm UTC](https://community.f5.com/t/https-redirection/50764/4 "2016-09-07T21:49:39Z")

</div>

minor change in above rule

```markup
when HTTP_REQUEST {
    log local0. "Incoming URI = [HTTP::uri]"
    if { [string tolower [HTTP::host]] equals "devcentral.com" && [string tolower [HTTP::uri]] starts_with "/groups/Research/" } {
        set uri [string map -nocase {"/groups/Research" "/devresearch"} [HTTP::uri]]
        log local0. "New URI = $uri"
        HTTP::redirect "https://f5.com[$uri]"
    }
}

```

---

<div class="post-metadata">

**Author:** ![Anush](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Anush](https://community.f5.com/u/Anush)\
**Post date:** [September 7, 2016, 10:26pm UTC](https://community.f5.com/t/https-redirection/50764/5 "2016-09-07T22:26:01Z")

</div>

again minor change

```markup
when HTTP_REQUEST {
    log local0. "Incoming URI = [HTTP::uri]"
    if { [string tolower [HTTP::host]] equals "devcentral.com" && [string tolower [HTTP::uri]] starts_with "/groups/Research/" } {
        set uri [string map -nocase {"/groups/Research" "/devresearch"} [HTTP::uri]]
        log local0. "New URI = $uri"
        HTTP::redirect "https://f5.com[http::uri $uri]"
    }
}

```

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [September 13, 2016, 5:13pm UTC](https://community.f5.com/t/https-redirection/50764/6 "2016-09-13T17:13:27Z")

</div>

Hi Anush,

accuracy and performance wise the code below would be most effective…

```markup
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
    HTTP::redirect "https://f5.com/devresearch/[string range [HTTP::uri] 17 end]"
}

```

… almost equals (but without -NOCASE support)…

```markup
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
    HTTP::redirect "https://f5.com/devresearch/[findstr [HTTP::uri] "/groups/Research/" 17 end]"
}

```

… closely followed by a …

```markup
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
    HTTP::redirect "https://f5.com/devresearch/[string range [HTTP::uri] [string length "/groups/Research/"] end]"
}

```

… almost equals (but without -NOCASE support) …

```markup
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
    HTTP::redirect "https://f5.com/devresearch/[findstr [HTTP::uri] "/groups/Research/" [string length "/groups/Research/"] end]"
}

```

… closely followed by the less accurate (the **[getfield]** search patter may occour multiple times and without -NOCASE support) method …

```markup
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
    HTTP::redirect "https://f5.com/devresearch/[getfield [HTTP::uri] "/groups/Research/" 2]"
}

```

… followed by the less accurate (the **[string map]** search patter may occour multiple times) and less performant method …

```markup
if { ( [HTTP::host] eq "devcentral.com" ) and ( [HTTP::path] starts_with "/groups/Research/" ) } then {
    HTTP::redirect "https://f5.com[string map [list "/groups/Research/" "/devresearch/"] [HTTP::uri]]"
}

```

_ **Update:** Included the **[findstr]** command._

Cheers, Kai

---

<div class="post-metadata">

**Author:** ![DJ\_Singh\_192109](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@DJ\_Singh\_192109](https://community.f5.com/u/DJ_Singh_192109)\
**Post date:** [September 13, 2016, 5:47pm UTC](https://community.f5.com/t/https-redirection/50764/7 "2016-09-13T17:47:04Z")

</div>

I think the below code would work best for you -

if { ( [HTTP::host] eq “[devcentral.com](http://devcentral.com)” ) and ( [HTTP::uri] starts\_with “/groups/Research/” ) } then { HTTP::redirect “[https://f5.com/devresearch/\](https://f5.com/devresearch/%5C)[string range [HTTP::uri] 17 end]” }
