0

I am trying to convert the following rewrite rule into a 'try_files':

location ~* \.(css|js) {
    if (!-f $request_filename) {
        rewrite ^/wp-content/w3tc/min/(.+\.(css|js))$ /wp-content/w3tc/min/index.php?file=$1 last;
        expires max;
    }
}

My new rule that I am shooting for:

location ~* \.(css|js) {
    try_files $uri /wp-content/w3tc/min/index.php?file=$request_basename;
    expires max;
}

A sample URI that is being generated:

http://mysite.com/wp-content/w3tc/min/88f17/default.include.60eaac.css

I found the following to get the basename of the URI:

map $request_uri $request_basename {
    ~/(?<captured_request_basename>[^/?]*)(?:\?|$) $captured_request_basename;
}

The problem I have is that '$request_basename' equals 'default.include.60eaac.css'. The application I am trying to work around (W3 Total Cache) needs '88f17/default.include.60eaac.css' passed to it.

Anyone know how I can modify the map rule to include the parent directory in the variable it generates? I kinda suck at regex...

1 Answer 1

0

You can capture the basename in a location block:

location ~ ^/wp-content/w3tc/min/(?P<request_basename>.*\.(css|js))$ {
    try_files $uri /wp-content/w3tc/min/index.php?file=$request_basename;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .