[feature] Add skip_location directive to ngx_http_rewrite

Dmitrii Chekaliuk d.chekaliuk at invisilabs.com
Thu Jan 17 10:07:51 UTC 2013

Hi guys,

I'm new to nginx-devel, so, please, take my apologies in case this 
question was already discussed and rejected. Nginx is awesome, but I 
think it lacks the flexibility of configuration selection, e.g. it can't 
throw away the selected config on demand within the rewrite phase to 
select another one without a need to actually rewrite URI. Think of 
Apache mod_rewrite's RewriteCond+RewriteRule, it would be great to have 
the ability to write something like this:

location ~ ^/some/path$  {
     if ($request_method !~* ^GET|HEAD$) { skip_location; }

     # ...

location ~ ^/some/path$ {
     # ...

to replicate mod_rewrite's:

RewriteCond %{REQUEST_URI} ^/some/path$
RewriteRule ...

RewriteCond %{REQUEST_URI} ^/some/path$
RewriteRule ...

I know we could rewrite original URI with method added, like 
$request_method/$uri, and make our location regexes aware of this, but 
what if such a logic is needed only for some locations? So, I suggest 
adding the before mentioned skip_location directive to the http_rewrite 
module. There is a commit on GitHub with the results of my research: 

What do you think?

Yours faithfully,

More information about the nginx-devel mailing list