Hi,
I’m working on setting up a new Nginx server, and not sure how to translate one of my ReWrite Rules.
The Rule is:
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !^nocache=true [NC]
RewriteCond %{HTTP_COOKIE} !nocache=true [NC]
RewriteCond /var/www/somesite/www/cache/$1.html -f
RewriteRule ^/(.*)/$ /var/www/somesite/www/cache/$1.html [L,QSA]
Or in English:
IF the Request is not a POST request
AND a cookie named nocache is not set or is not true
AND a query string parameter named nocache is not set or is not true
AND a file, [Insert_Pattern_Match].html, exists in the subfolder cache.
Serve the file silently with no redirect and stop processing rules. Otherwise continue processing rules.
[Insert_Pattern_Match] Comes from the “slug”.
For example, a visit to:
http://www.mysite.com/frogs/
would look for a file:
<WEBROOT>/cache/frogs.html
I’m thinking it would be something like:
# Try a static file in cache folder, then a static file, then a static directory, then pass to PHP.
location ~ ^/([a-zA-Z0-9\\-\\_]+)/$ {
try_files /cache/$1.html $uri $uri/ /Index.php?rt=$1;
}
But I’m not sure that’s correct or efficient, and I don’t know how to integrate the other conditions into it.