# Using iRules for Redirects with strings

**URL:** <https://community.f5.com/t/using-irules-for-redirects-with-strings/3587>\
**Category:** Technical Forums\
**Tags:** config, irules, devops, application-delivery, http-redirect\
**Created:** [September 24, 2013, 4:43pm UTC](https://community.f5.com/t/using-irules-for-redirects-with-strings/3587 "2013-09-24T16:43:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_H\_117248](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@Bob\_H\_117248](https://community.f5.com/u/Bob_H_117248)\
**Post date:** [September 24, 2013, 4:43pm UTC](https://community.f5.com/t/using-irules-for-redirects-with-strings/3587/1 "2013-09-24T16:43:18Z")

</div>

I’m looking for a way to redirect as follows:

[http://mytraining.site.com?\_cid=xxxxx](http://mytraining.site.com?%5C_cid=xxxxx) redirecting to [http://www.site.com/training/index.htm?\_cid=xxxxx](http://www.site.com/training/index.htm?%5C_cid=xxxxx)

The xxxxx is a variety of numbers. Right now my rule cuts off the ?\_cid=xxxxx

Any help is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![What\_Lies\_Bene1](https://avatars.discourse-cdn.com/v4/letter/w/59ef9b/32.png) [@What\_Lies\_Bene1](https://community.f5.com/u/What_Lies_Bene1)\
**Post date:** [September 24, 2013, 4:53pm UTC](https://community.f5.com/t/using-irules-for-redirects-with-strings/3587/2 "2013-09-24T16:53:21Z")

</div>

HTTP::redirect “[http://www.site.com/training\[HTTP::path]?\](http://www.site.com/training%5C%5BHTTP::path%5D?%5C)[[HTTP::query]”

---

<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:** [September 24, 2013, 4:56pm UTC](https://community.f5.com/t/using-irules-for-redirects-with-strings/3587/3 "2013-09-24T16:56:45Z")

</div>

Something like this maybe:

```tcl
when HTTP_REQUEST {
    set query ""
    if { [URI::query [HTTP::uri] _cid] ne "" } {
        set query "?_cid=[URI::query [HTTP::uri] _cid]"
    }
    HTTP::redirect "http://www.site.com/training/index.htm${query}"
}

```

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [September 24, 2013, 5:05pm UTC](https://community.f5.com/t/using-irules-for-redirects-with-strings/3587/4 "2013-09-24T17:05:09Z")

</div>

Or maybe something like this example? This assumes that [mytraining.site.com](http://mytraining.site.com) and [www.site.com](http://www.site.com) resolve to the same virtual server IP address.

```tcl
when HTTP_REQUEST {

   if {[HTTP::uri] contains "_cid=" and not ([HTTP::path] starts_with "/training/index.htm"}{

      HTTP::redirect "http://www.site.com/training/index.htm?_cid=[URI::query [HTTP::uri] _cid]"
   }
}

```

Aaron
