title: Wildcard request / location in nginx?
body: <p>I have a script that increments a global revision number with each deployment of my website. This number is then mapped into the HTML that loads CSS, JavaScript and sprite assets. This is used as a cache-busting strategy.</p>
  
  <p>e.g <code>&lt;link rel="stylesheet" href="/css/screen_r123.css" type="text/css" /&gt;</code></p>
  
  <p>In Apache, I would rewrite these incrementing URLs back to the actual assets like this:</p>
  
  <pre><code>RewriteRule ^css/screen_r(.*).css$ /css/screen_min.css [L]
  </code></pre>
  
  <p><strong>How would I do the same in nginx</strong>? I'm not sure where to place the regex matching logic.</p>
  
  <p><em>Note: I don't want to append a query <code>?r=123</code> to the end of the URI because it feels incorrect to pass a query to a static asset, plus I'm behind a Varnish proxy that doesn't include queries in its cache hashes</em></p>
  
  <hr>
  
  <p>Here is my current nginx conf for my site:</p>
  
  <pre><code>server {
    listen 8080;
    server_name domain.com www.domain.com
    port_in_redirect off;
  
    root /usr/share/nginx/mydomain.com/public;
    index index.html index.php;
  
    #set long expiry for assets
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
      expires max;
      log_not_found off;
    }
  
    location / {
      #FOLLOWING LINE DOES NOT WORK AS INTENDED
      rewrite ^/css/screen_r(.*).css$ /css/screen.css last;
  
      # Check if a file or directory index file exists, else route it to index.php.
      try_files $uri $uri/ /index.php;
    }
  
    location ~* \.php$ {     
      fastcgi_pass   unix:/tmp/php5-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include        fastcgi_params;
      fastcgi_param APPLICATION_ENV "production";
      fastcgi_split_path_info ^(.+.php)(.*)$;
    }
  
    add_header "X-UA-Compatible" "IE=Edge,chrome=1";
    add_header Cache-Control "public max-age=60";
  }
  </code></pre>