back-reference from if() and rewrite?

ST smntov at
Mon Jun 5 15:15:54 UTC 2017


I need to translate following rule from apache to nginx:

RewriteCond %{QUERY_STRING} id=([^&]*) [NC,OR]
RewriteCond %{QUERY_STRING} daily=([^&]*) [NC]
RewriteCond %{REQUEST_URI} !mobSpecCycle [NC]
RewriteCond %{REQUEST_URI} !mobSpecTheme [NC]
RewriteRule ^rss\/mobSpec([^\/]+)/?$ /rss/mobSpec$1/mobSpec$1_%1.html

which, e.g. rewrites




I started as follows

if ($args ~ id=([^&]*)|daily=([^&]*)) {
   rewrite ^/rss\/mobSpec([^\/]+)/?$ /rss/mobSpec$1/mobSpec$1_$2.html

However I don't know how to backrefernce id=([^&]*) in the rewrite rule?
I put $2 there, but it doesn't work... apache has %1 for
back-referencing matches from the RewriteCond.

1. How do I back-referencing matches from if () in nginx within
following rewrite?

2. Any ideas how I can add the last two condition?
RewriteCond %{REQUEST_URI} !mobSpecCycle [NC]
RewriteCond %{REQUEST_URI} !mobSpecTheme [NC]

Thank you in advance!

More information about the nginx mailing list