NGINX重写规则,将部分URL传递给PHP - Wishlist Member

In Nginx, how can I select the bold part of the URL below? 2013 and 12 are relative to the date so the rule needs to be flexible to work future locations.

example.com/wp-content/uploads/2013/12/sometime.pdf

The end result should look something like: index.php?method=2013/12/sometime.pdf

Current rewrite rule

I have tried with the following but this will only return the last letter of the URL.

rewrite ^/wp-content/uploads/2013/12/sometime.pdf /index.php?method=$1

Thanks!

This expression will rewrite anything in the uploads folder, without a known extension, and passes the two parts of the URL as required:-

rewrite ^/wp-content/uploads/(.*)\.(?!css|js|png|jpe?g|gif)(.*)$ /index.php?method=$1.$2

$1, i.e. the first "(.*)" is anything between /wp-content/uploads/ and the . of the file extension.

$2, i.e. the second "(.*)" is anything after the matched . of the file extension,

Negative look aheads are the trick here: (?!.....)

If you don't have any specifics for the URL , you can do a normal location block, with a tiny bit of regex

location ^~ /wp-content/uploads/(.*) {
  try_files /index.php?method=$1 =404;
}

To use the wishlist member plugin in wordpress with nginx, add the following rule to parse files through the wlmfile method and apply the correct permissions.

location / {
    index index.php index.html index.htm;
    rewrite ^/wp-content/uploads/(.*)\.(?!css|js|png|jpe?g|gif)(.*)$ /index.php?wlmfile=$1.$2 redirect;
    try_files $uri $uri/ /index.php?q=$uri&$args;
}