On Wed, Sep 26, 2007 at 04:18:43PM +1200, Philip Murray wrote:
Is it possible to express the following Apache rewrite rule in Nginx?
RewriteCond %{QUERY_STRING} !^nobranding$
RewriteCond %{REQUEST_FILENAME} ^/assets/XL/([^.]+)\.([jpegif]+)$
RewriteCond /usr/local/www/assets-nz/XL/%1.branded.%2 -f
RewriteRule ^/([^.]+)\.([jpeg]+)$ /$1.branded.$2
In Nginx, this would be in a location block with an alias, so
location /assets {
alias /usr/local/www/assets-nz/;
... rewrites go here ...
}
But, I understand you can't rewrite with an alias present? So how can
I implement the above Apache rewrite?
Try
location /assets {
if ($args = nobranding) {
rewrite ^(.+)$ /nobranding$1 last;
}
rewrite ^/assets/XL/(.+)\.(jpeg|jpg|gif) /XL/$1.branded.$2;
root /usr/local/www/assets-nz;
error_page 404 = /nobranding/assets$uri;
}
location /nobranding/assets {
internal;
alias /usr/local/www/assets-nz/;
}