back-reference from if() and rewrite?

ST smntov at gmail.com
Mon Jun 5 15:15:54 UTC 2017


Hello,

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
[QSA,NC,L]

which, e.g. rewrites

/rss/mobSpecArticle/?id=26422

into 

/rss/mobSpecArticle/mobSpecArticle_26422.html

I started as follows

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

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