Question: I have these rewrite rules (I tried both with no avail):

```
location ~* "^/([a-z0-9]{32})\.png$" {
  rewrite ^ /index.php?page=log&id=$1 last;
} 

```

and

```
location ~* "/(?<hash>[a-z0-9]{32})\.png" {
  rewrite ^ /index.php?page=log&id=$hash;
}

```

and

```
location / {
  try_files $uri $uri/ @rewrites;
}

location @rewrites {
  rewrite "^/([a-zA-Z0-9]{32})\.png$" /index.php?page=log&id=$1 last;
  #...
}

```

Basically, I want the URL `http://example.com/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png` to actually pass the parameters to my `index.php` script, and in the script, I got:

```php
$db->save_hash($_GET['id']);
header('Content-type: image/png');
readfile('images/beacon.png');
break;

```

But nginx is giving me a "not found", but other rewrites work fine. What gives?

Answer: 
this one worked for me:

```
    location / { 
    rewrite "/([a-z0-9]{32})\.png" /index.php?page=log&id=$1 break;
    }

```

Or if you want separeted location:

```
location ~* "/([a-z0-9]{32})\.png" {
rewrite /(.*) /index.php?page=log&id=$1 last;
}

```
As per nginx documentation of how the [`location`](http://nginx.org/en/docs/http/ngx_http_core_module.html#location) directive works:

> 
> A location can either be defined by a prefix string, or by a regular expression. 
>  ...
>  A search of regular expressions terminates on the first match, and the corresponding configuration is used.
> 
> 
> 

Based on addition information [from your own answer](https://serverfault.com/a/471867/151339) to this very question, it would seem like you intend on having several location directives to apply simultaneously right at the very same time, which is explicitly not allowed as per the unambiguous documentation.

Remember, nginx is faster and cleaner by design. So, don't expect the quirks!