# Block bot on uri with query\_string

**URL:** <https://www.ruby-forum.com/t/block-bot-on-uri-with-query-string/245872>\
**Category:** NGINX\
**Created:** [July 28, 2013, 4:56am UTC](https://www.ruby-forum.com/t/block-bot-on-uri-with-query-string/245872 "2013-07-28T04:56:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [July 28, 2013, 4:56am UTC](https://www.ruby-forum.com/t/block-bot-on-uri-with-query-string/245872/1 "2013-07-28T04:56:32Z")

</div>

Hi All,

Been trying to block bots from accessing a URI that has a query\_string  
“action=get\_it”, i tried below

```
    location ~* \?(action=get_it)$ {

            if ( $http_user_agent ~

```

(crawl|Googlebot|Slurp|spider|bingbot|tracker|click|parser|spider)) {

```
                    return 404;

                    break;

            }

     }

```

i just learned that location does not match query string, if i do the  
is\_arg i cant do nested if, anyone able to do this before?

TIA.

Regards,

Ron

---

<div class="post-metadata">

**Author:** ![ron\_ramos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dc4da7/32.png) [@ron\_ramos](https://www.ruby-forum.com/u/ron_ramos)\
**Post date:** [July 28, 2013, 11:08am UTC](https://www.ruby-forum.com/t/block-bot-on-uri-with-query-string/245872/2 "2013-07-28T11:08:37Z")

</div>

On Sun, Jul 28, 2013 at 11:55 AM, ron ramos [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> TIA.

I don’t remember the exact syntax but something like this should work:

if ($arg\_action = get\_it) { set $no\_bot 1; }  
if ($http\_user\_agent ~ ) { set $is\_bot 1; }  
if ($no\_bot$is\_bot = 11) { return 404; }

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![ron\_ramos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dc4da7/32.png) [@ron\_ramos](https://www.ruby-forum.com/u/ron_ramos)\
**Post date:** [July 28, 2013, 12:22pm UTC](https://www.ruby-forum.com/t/block-bot-on-uri-with-query-string/245872/3 "2013-07-28T12:22:13Z")

</div>

oh cool thanks i get what you mean. thanks for the help!

Regards,  
Ron

---

<div class="post-metadata">

**Author:** ![ron\_ramos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dc4da7/32.png) [@ron\_ramos](https://www.ruby-forum.com/u/ron_ramos)\
**Post date:** [July 28, 2013, 2:51pm UTC](https://www.ruby-forum.com/t/block-bot-on-uri-with-query-string/245872/4 "2013-07-28T14:51:13Z")

</div>

On 28 Jul 2013 10:08, “edogawaconan” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > if ( $http_user_agent ~
> > 
> > ```
> > 
> > i just learned that location does not match query string, if i do the  
> > is\_arg  
> > i cant do nested if, anyone able to do this before?
> > 
> > TIA.
> 
> I don’t remember the exact syntax but something like this should work:
> 
> if ($arg\_action = get\_it) { set $no\_bot 1; }  
> if ($http\_user\_agent ~ ) { set $is\_bot 1; }  
> if ($no\_bot$is\_bot = 11) { return 404; }

I would personally use a map{} which examined both variables and then a  
single if() to take action based on the map’s result.

I’d be interested in any official comment from nginx staff about the  
relative merits of these approaches …

J
