# Redirect only every 2nd or 3rd request

**URL:** <https://www.ruby-forum.com/t/redirect-only-every-2nd-or-3rd-request/231836>\
**Category:** NGINX\
**Created:** [September 2, 2014, 10:59am UTC](https://www.ruby-forum.com/t/redirect-only-every-2nd-or-3rd-request/231836 "2014-09-02T10:59:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [September 2, 2014, 10:59am UTC](https://www.ruby-forum.com/t/redirect-only-every-2nd-or-3rd-request/231836/1 "2014-09-02T10:59:39Z")

</div>

I’m trying to set up a rule which is going to redirect only every second  
or  
third request only if the URL contains a specific string.  
I did already the redirect based on a string in the URL but I can’t find  
how  
to redirect only every second on third request:

if ($request\_uri ~ ._.WHATEVER\_STRING._) {  
if (this is the 2nd request than) {  
rewrite ^/(.\*) WHATEVER\_URL;  
}  
}

Posted at Nginx Forum:

> **[redirect only every 2nd or 3rd request](https://forum.nginx.org/read.php?2,253011,253011#msg-253011)**
>
> I'm trying to set up a rule which is going to redirect only every second or third request only if the URL contains a specific string. I did already the redirect based on a string in the URL but I can't find how to redirect only every second on third...
