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: 
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!
Mark pointed out so I started removing all the included files, and boiled down to:

`/etc/nginx/conf.d/h5bp.conf`

that contains

```
# Basic h5bp rules

include /etc/nginx/conf.d/expires.conf;
include /etc/nginx/conf.d/x-ua-compatible.conf;
include /etc/nginx/conf.d/protect-system-files.conf;

```

the `expires.conf` got

```
# Expire rules for static content

# No default expire rule. This config mirrors that of apache as outlined in the
# html5-boilerplate .htaccess file. However, nginx applies rules by location,
# the apache rules are defined by type. A concequence of this difference is that
# if you use no file extension in the url and serve html, with apache you get an
# expire time of 0s, with nginx you'd get an expire header of one month in the
# future (if the default expire rule is 1 month). Therefore, do not use a
# default expire rule with nginx unless your site is completely static

# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html|xml|json)$ {
  expires -1;
  access_log /var/log/nginx/static.log;
}

# Feed
location ~* \.(?:rss|atom)$ {
  expires 1h;
  add_header Cache-Control "public";
}

# Favicon
location ~* \.ico$ {
  expires 1w;
  access_log off;
  add_header Cache-Control "public";
}

# Media: images, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|gz|svg|svgz|mp4|ogg|ogv|webm)$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}

# CSS and Javascript
location ~* \.(?:css|js)$ {
  expires 1y;
  access_log off;
  add_header Cache-Control "public";
}

# WebFonts
# If you are NOT using cross-domain-fonts.conf, uncomment the following directive
location ~* \.(ttf|ttc|otf|eot|woff|font.css)$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}

```

commenting that `expires.conf`, then it starts working, how can I fix this?