# iRule URI replace help

**URL:** <https://community.f5.com/t/irule-uri-replace-help/3156>\
**Category:** Technical Forums\
**Tags:** irules, application-delivery\
**Created:** [August 22, 2018, 12:22am UTC](https://community.f5.com/t/irule-uri-replace-help/3156 "2018-08-22T00:22:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Domai\_23823](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@Domai\_23823](https://community.f5.com/u/Domai_23823)\
**Post date:** [August 22, 2018, 12:22am UTC](https://community.f5.com/t/irule-uri-replace-help/3156/1 "2018-08-22T00:22:41Z")

</div>

Hello All - I need help to fix the below iRule

Requirement is when the user types in [https://apple.api.com/e/apple/console/](https://apple.api.com/e/apple/console/) the uri /e/apple/ should be replaced by /console so its going to be [https://apple.api.com/console/](https://apple.api.com/console/) The below iRule accomplishes that but when user types in [https://apple.api.com/e/apple/console](https://apple.api.com/e/apple/console) without the ‘/’ after console it does nothing. It only works when user types ‘/’ at the end.

```tcl
when HTTP_REQUEST {
    log local0. "Incoming URI = [HTTP::uri]"
    if { [string tolower [HTTP::uri]] starts_with "/e/apple/" } {
        set uri [string map -nocase {"/e/apple/" "/"} [HTTP::uri]]
        log local0. "New URI = $uri"
        HTTP::uri $uri
        virtual apple.api_vs_4001
        log local0. "Host header is [HTTP::host]"
    }
}

```

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [August 22, 2018, 1:04am UTC](https://community.f5.com/t/irule-uri-replace-help/3156/2 "2018-08-22T01:04:34Z")

</div>

Can we assume the log statement is returning the correct value?

When you say “it does nothing”, can you elaborate?

Can the server actually handle the URL without the trailing “/”?

---

<div class="post-metadata">

**Author:** ![youssef1](https://avatars.discourse-cdn.com/v4/letter/y/ed655f/32.png) [@youssef1](https://community.f5.com/u/youssef1)\
**Post date:** [August 22, 2018, 9:44am UTC](https://community.f5.com/t/irule-uri-replace-help/3156/3 "2018-08-22T09:44:27Z")

</div>

Hi Domai,

I understand your problem. If you not put / after console at the end of th uri, it’s not working. I advise you to rewrite your uri in order to add “/” at the end of uri if it’s not present.

Please try this Irule, it will fix your problem

```tcl
when HTTP_REQUEST {
    log local0. "Incoming URI = [HTTP::uri]"
    if { [string tolower [HTTP::uri]] starts_with "/e/apple/" } {

        if { [string tolower [HTTP::uri]] contains "/console/" } {
            set uri [string map [list "/e/apple/" "/" "/console" "/console/"] [HTTP::uri]]
        } else {
            set uri [string map -nocase {"/e/apple/" "/"} [HTTP::uri]]
        }

        log local0. "New URI = $uri"
        HTTP::uri $uri
        virtual apple.api_vs_4001
        log local0. "Host header is [HTTP::host]"
    }
}

```

Keep me in touch if it working for your.

Regards

---

<div class="post-metadata">

**Author:** ![Domai\_23823](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@Domai\_23823](https://community.f5.com/u/Domai_23823)\
**Post date:** [August 22, 2018, 12:23pm UTC](https://community.f5.com/t/irule-uri-replace-help/3156/4 "2018-08-22T12:23:50Z")

</div>

Hello Kevin when I say nothing I meant that page does not load it just hangs.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [August 22, 2018, 12:40pm UTC](https://community.f5.com/t/irule-uri-replace-help/3156/5 "2018-08-22T12:40:23Z")

</div>

I don’t see anything particularly wrong with the iRule logic, so I have to wonder if the server actually understands the “/console” URI (vs. “/console/”).

---

<div class="post-metadata">

**Author:** ![Domai\_23823](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@Domai\_23823](https://community.f5.com/u/Domai_23823)\
**Post date:** [August 22, 2018, 2:29pm UTC](https://community.f5.com/t/irule-uri-replace-help/3156/6 "2018-08-22T14:29:09Z")

</div>

And the log statement is returning the correct value only when user types in /in the end or else it does not return the correct value. For example when user types /p/apple/console/ it shows incoming uri as /p/apple/console/ and new uri as /console/

But when user types in /p/apple/console, it shows incoming uri as /console/ and that that is it.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [August 22, 2018, 2:32pm UTC](https://community.f5.com/t/irule-uri-replace-help/3156/7 "2018-08-22T14:32:13Z")

</div>

This may require deeper inspection of the HTTP traffic flow, as there maybe client side processing affecting the interaction. Can you display the results of a simple Fiddler capture (with both URLs)?

---

<div class="post-metadata">

**Author:** ![Domai\_23823](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@Domai\_23823](https://community.f5.com/u/Domai_23823)\
**Post date:** [August 22, 2018, 11:10pm UTC](https://community.f5.com/t/irule-uri-replace-help/3156/8 "2018-08-22T23:10:20Z")

</div>

I have the screenshot…can I get your email so that I can mail it to you directly. I am unable to upload it here using insert image option.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [August 22, 2018, 11:47pm UTC](https://community.f5.com/t/irule-uri-replace-help/3156/9 "2018-08-22T23:47:45Z")

</div>

Sent you a private message
