: Nginx Rewrite causing problems I wrote a little php script that reads and compresses css and javascript files. I used a rewrite to automatically redirect all resources to that script. The rule
I wrote a little php script that reads and compresses css and javascript files. I used a rewrite to automatically redirect all resources to that script. The rule looks like this:
rewrite ^(/.*.(css|js))$ /compress.php?file=&type=;
However this somehow disables these settings:
location ~* .(css|js|gif|jpe?g|png|ico)$ {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
How do I get Nginx to still use these settings?
More posts by @Bryan171
1 Comments
Sorted by latest first Latest Oldest Best
You can try to create a separate block for the css / js files, and include the rewrite directive inside that directive, like this:
location ~* (?<filename>.+.(?<type>css|js))$ {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
rewrite ^ /compress.php?file=$filename&type=$type;
}
Here I use regex captures on the location directive, and capture to named variables. It is just a matter of taste how you do the captures though.
And then reduce the other block to:
location ~* .(?:gif|jpe?g|png|ico)$ {
I use ?: prefix here to indicate that we don't need to make any regex captures.
If that doesn't work, then you have to set the cache headers inside your compress.php script with header() function.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.