I converted most of my mod_rewrite Apache HTTPd rules to the nginx HttpRewrite module (which calls PHP-FPM via FastCGI on every dynamic request). Simple rules defined by hard locations work fine:
location = /favicon.ico { rewrite ^(.*)$ /_core/frontend.php?type=ico&file=include__favicon last; }
I'm still having problems with regular expressions that are parsed in mod_rewrite like this (note that I accept trailing slashes as part of the rules, and also add a query string to each query):
mod_rewrite
# File handler RewriteRule ^([a-z0-9-_,+=]+)\.([az]+)$ _core/frontend.php?type=$2&file=$1 [QSA,L]
I came up with the following server configuration for the site, but after analyzing the request (for example, GET /user/auth ), I met unrivaled rules:
nginx attempt to rewrite
location / { # File handler rewrite ^([a-z0-9-_,+=]+)\.([az]+)?(.*)$ /_core/frontend.php?type=$2&file=$1&$3 break; # Page handler rewrite ^([a-z0-9-_,+=]+)(\/*)?(.*)$ /_core/frontend.php?route=$1&$2 break; rewrite ^([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)(\/*)?(.*)$ /_core/frontend.php?route=$1/$2&$3 break; rewrite ^([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)(\/*)?(.*)$ /_core/frontend.php?route=$1/$2/$3&$4 break; }
What would you recommend for working with my file handler (it's just filename.ext ) and my page handler (which is a unique route request with three properties defined by a forward slash)?
As I have not yet received a response from this, I am also not sure that this will override my PHP parser, which is defined using location ~ \.php {} , which is included before these rewrite rules.
Bonus points if I can solve parsing problems without having to use a new rule for each number of route properties.