Use variable in regex rewrite test on nginx

I have a network of multilingual Wordpress applications running on nginx. I am trying to configure caching using the w3 shared cache. I am 99%, but I just adhered to one rule.

I found a few instructions that pointed me to this rewrite rule in order to rewrite css and js mini files with beautiful URLs:

# Rewrite minified CSS and JS files location ~* \.(css|js) { if (!-f $request_filename) { rewrite ^/wp-content/w3tc/min/(.+\.(css|js))$ /wp-content/w3tc/min/index.php?file=$1 last; } } 

I modified it to work in my multi-node environment:

 rewrite ^/wp-content/w3tc-$host/min/(.+\.(css|js))$ /wp-content/w3tc-$host/min/index.php?file=$1 last; 

However, I found out that the test does not interpret the $host variable; instead, it actually tests the string "$host" . Is there a way to actually use the value of the $host variable in a test? Alternatively, it would be nice to use a general rule, for example:

 rewrite ^/wp-content/w3tc-.*?/min/(.+\.(css|js))$ /wp-content/w3tc-$host/min/index.php?file=$1 last; 

I am open to the best suggestions on this subject - regular expression is not a strong point for me.

And finally, for those who are looking for an alternative answer: you can get a minimum by simply disabling "Rewrite URL structure" in the settings. This is purely for urls for mini files.

+4
source share

All Articles