# How to match these urls?

**URL:** <https://www.ruby-forum.com/t/how-to-match-these-urls/193252>\
**Category:** NGINX\
**Created:** [August 14, 2010, 4:45am UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252 "2010-08-14T04:45:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 4:45am UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/1 "2010-08-14T04:45:12Z")

</div>

requests like these are hitting my server, and i want to catch these  
requests, and return ‘not found’ from nginx. i dont want it to hit my  
fastcgi backend.

[13/Aug/2010:19:39:26 -0700] “POST /%5C%22http:%5C/%5C/  
[photos-b.ak.fbcdn.net](http://photos-b.ak.fbcdn.net)%5C/photos-ak-snc1%5C/v43%5C/64%5C/68931197560%5C/app\_2\_68931197560\_3211.gif%5C%22  
HTTP/1.1” 404 103 “-” “Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5;  
en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8” 0.087 US

how do i match requests with url starting like this:

/%5C%22http:%5C/%5C/

thanks!

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 4:48am UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/2 "2010-08-14T04:48:42Z")

</div>

On Sat, Aug 14, 2010 at 03:43, kevin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> and return ‘not found’ from nginx.

How about returning 444 instead?

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 3:03pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/3 "2010-08-14T15:03:45Z")

</div>

On 08/14/2010 05:25 AM, kevin wrote:

> and take care of them from nginx, and not hit the fastcgi backend.  
> What does the referer look like? This request looks like it is generated  
> by  
> some script and you probably want to find out what the source for them  
> is.  
> Are you sure that it’s not one of your own scripts/php pages that  
> generates  
> these?

Regards,  
Dennis

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 7:08pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/4 "2010-08-14T19:08:27Z")

</div>

On Fri, Aug 13, 2010 at 07:43:58PM -0700, kevin wrote:

> how do i match requests with url starting like this:
> 
> /%5C%22http:%5C/%5C/

Try  
location /"http:// {

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 8:44pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/5 "2010-08-14T20:44:26Z")

</div>

On Sat, Aug 14, 2010 at 10:07 AM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8" 0.087 US
> > 
> > how do i match requests with url starting like this:
> > 
> > /%5C%22http:%5C/%5C/
> 
> Try  
> location /"http:// {

thanks for this. can you give complete code of how to return a 404 or  
302  
for these matched requests?  
thank you!

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 8:50pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/6 "2010-08-14T20:50:18Z")

</div>

On Sat, Aug 14, 2010 at 11:42 AM, kevin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > %5C/photos-ak-snc1%5C/v43%5C/64%5C/68931197560%5C/app\_2\_68931197560\_3211.gif%5C%22
> 
> I tried this, but did not help

```
    location /\"http:\/\/ {
        access_log logs/junk.log wtop;
        rewrite ^/(.*) www.XXX.com permanent;
    }

```

it does not catch it. it is still hitting my fastcgi backend

81.192.X.X - - [14/Aug/2010:11:46:04 -0700] “POST /%5C%22http:%5C/%5C/  
[photos-b.ak.fbcdn.net](http://photos-b.ak.fbcdn.net)%5C/photos-ak-snc1%5C/v43%5C/240%5C/350031875244%5C/app\_2\_350031875244\_2165.gif%5C%22  
HTTP/1.1” 404 103 “-” “Mozilla/5.0 (Windows; U; Windows NT 5.1; fr;  
rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729)  
;ShopperReports” 0.084 MA

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 8:54pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/7 "2010-08-14T20:54:24Z")

</div>

On Sat, Aug 14, 2010 at 6:02 AM, Dennis J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > How about returning 444 instead?

it is a facebook app, and i do not have control over these requests.

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 5:26am UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/8 "2010-08-14T05:26:09Z")

</div>

2010/8/13 Nuno MagalhÃ£es [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> On Sat, Aug 14, 2010 at 03:43, kevin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > and return ‘not found’ from nginx.
> 
> How about returning 444 instead?
> 
> what is 444? i dont care what i return. i just want to catch these requests  
> and take care of them from nginx, and not hit the fastcgi backend.

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 9:16pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/9 "2010-08-14T21:16:03Z")

</div>

On Sat, Aug 14, 2010 at 12:01 PM, Edho P Arief [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > > > fastcgi backend.  
> > > > > how do i match requests with url starting like this:  
> > > > > rewrite ^/(.\*) [www.XXX.com](http://www.XXX.com) permanent;  
> > > > > }
> > 
> > it does not catch it. it is still hitting my fastcgi backend
> 
> put it in the topmost of your server block.

yes i have it in the top most position in server block. all other  
location  
sections are below this and it still does not catch it. it is going to  
the  
location that matches the last block  
location / {

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 14, 2010, 9:02pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/10 "2010-08-14T21:02:35Z")

</div>

On Sun, Aug 15, 2010 at 1:49 AM, kevin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > > [13/Aug/2010:19:39:26 -0700] Â "POST /%5C%22http:%5C/%5C/  
> > > > Try  
> > > > it does not catch it. it is still hitting my fastcgi backend

put it in the topmost of your server block.

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

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 15, 2010, 9:40am UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/11 "2010-08-15T09:40:27Z")

</div>

On Sat, Aug 14, 2010 at 12:14:46PM -0700, kevin wrote:

> > > > > > requests like these are hitting my server, and i want to catch these
> > > 
> > > ```
> > > location /\"http:\/\/ {
> > > 
> > > ```
> 
> yes i have it in the top most position in server block. all other location  
> sections are below this and it still does not catch it. it is going to the  
> location that matches the last block  
> location / {

Sorry, the slashes should be escaped, this is working configuration:

```
    location ^~ /\\"http:\\/\\/ {
        return 404;
    }

```

“^~” is to disable regex locations.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 15, 2010, 3:46pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/12 "2010-08-15T15:46:16Z")

</div>

On Sun, Aug 15, 2010 at 12:39 AM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > > On Sat, Aug 14, 2010 at 10:07 AM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> > > > > 
> > > > > > > [13/Aug/2010:19:39:26 -0700] "POST /%5C%22http:%5C/%5C/
> > > > 
> > > > ```
> > > > }
> > > > 
> > > > ```
> 
> the

thanks a lot! this catches it and returns 404!

is it possible to customize the 404 message for this location?  
thanks!

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [August 15, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/how-to-match-these-urls/193252/13 "2010-08-15T19:31:38Z")

</div>

On Sun, Aug 15, 2010 at 06:45:09AM -0700, kevin wrote:

> is it possible to customize the 404 message for this location?  
> thanks!

```
 location ^~ /\\"http:\\/\\/ {
     return 404;
     error_page 404 /bad.html;
 }

 location = /bad.html {
     root /path/to/page;
 }

```

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
