# HTTP URI redirect

**URL:** <https://community.f5.com/t/http-uri-redirect/21443>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [July 24, 2008, 4:46pm UTC](https://community.f5.com/t/http-uri-redirect/21443 "2008-07-24T16:46:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_X\_20743](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@David\_X\_20743](https://community.f5.com/u/David_X_20743)\
**Post date:** [July 24, 2008, 4:46pm UTC](https://community.f5.com/t/http-uri-redirect/21443/1 "2008-07-24T16:46:38Z")

</div>

Hi

I am not sure if the following http uri redirect is possible or not.

Please give me a hint. Thanks

when the client request

[http://test.com/test.html](http://test.com/test.html)

The F5 will check the URI for test.html,

If matching, then rediect to

[http://test.com/test1.html](http://test.com/test1.html)

[http://test.com/test2.html](http://test.com/test2.html)

[http://test.com/test3.html](http://test.com/test3.html)

with round robin Method.

Really confused here. If customers were asking for direct traffic to different pool, things will be lot easier for me. Do not know how to direct the traffic to three URI with round robin, please help. Thanks

---

<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:** [July 24, 2008, 5:04pm UTC](https://community.f5.com/t/http-uri-redirect/21443/2 "2008-07-24T17:04:44Z")

</div>

Something like this?

```tcl
when RULE_INIT {  
    
      Initialize a global counter  
     set ::redirect_counter 1  
  }  
  when HTTP_REQUEST {  
    
      Check if URI is /test.html  
     if {[HTTP::uri] eq "/test.html"}{  
    
         Redirect client according to the counter value  
        HTTP::redirect "http://[HTTP::host]/test${::redirect_counter}"  
    
         Increment the counter  
        incr ::redirect_counter  
    
         Reset the counter if it's over the limit  
        if {$::redirect_counter > 3}{  
           set ::redirect_counter 1  
        }  
     }  
  }

```

If the URI’s don’t literally ending with a number, you could use something like this:

```tcl
when RULE_INIT {  
    
      Initialize a global counter  
     set ::redirect_counter 1  
  }  
  when HTTP_REQUEST {  
    
      Check if URI is /test.html  
     if {[HTTP::uri] eq "/test.html"}{  
    
         Redirect client according to the counter value  
        switch $::redirect_counter {  
           1 {  
              HTTP::redirect "http://[HTTP::host]/testUrlOne"  
           }  
           2 {  
              HTTP::redirect "http://[HTTP::host]/testUrlTwo"  
           }  
           3 {  
              HTTP::redirect "http://[HTTP::host]/testUrlThree"  
           }  
        }  
         Increment the counter  
        incr ::redirect_counter  
    
         Reset the counter if it's over the limit  
        if {$::redirect_counter > 3}{  
           set ::redirect_counter 1  
        }  
     }  
  }

```

Aaron
