Nginx mutiple conditions for rewrite <p>my nginx configuration as following</p> <pre><code> location /eicnews/ { set $con ""; if ($request_uri ~ ^/eicnews\/(.*)$) { set $con A; } if ($request_uri ~ ^/eicnews\/$) { set $con "${con}B"; } if ($con = A) { rewrite ^/eicnews\/eicnewscontent_(.*)\.shtml$ http://news.abc.cn/eic/news_$1.shtml permanent; } if ($con = AB) { rewrite ^/eicnews\/(.*)$ http://news.abc.cn/eic permanent; } } </code></pre> <p>my configuration means that 1.if clients request directoty named "/eicnews/" will be rewrited to url/dir 2.if clients request the files included the directoty named "/eicnews/" will be rewrited to url/dir/files</p> <p>But now there tow kinds file names in "/eicnews/" ,eicnewscontent_xxxx.shtml and eicnewslist_xxxx.shtml ,I wanna if the prefix "eicnewscontent" files be rewrited to <a href="http://news.abc.cn/eic/news_" rel="nofollow">http://news.abc.cn/eic/news_</a>$1.shtml and the prefix "eicnewslist" will be rewrited to <a href="http://news.abc.cn/eic" rel="nofollow">http://news.abc.cn/eic</a>. </p> <p>Thank You ALL!!!!</p> <p>I mean that,there 2 kinds prefix file in the directoty,such as eicnewslist_xxxxx.shtml and eicnewscontent_xxxxx.shtml, prefix "eicnewslist" rewrite to one url,prefix "eicnewscontent" rewrite to the other url.I want it as following.Syntax is OK. But it doesn't works. </p> <pre><code>location = /eicnews/ { rewrite ^/eicnews/eicnewslist(_.*\.shtml)$ http://news.smartjs.cn/eic$1 permanent; } location /eicnews/ { rewrite ^/eicnews/eicnewscontent(_.*\.shtml)$ http://news.smartjs.cn/eic/news_xx.shtml$1 permanent; } </code></pre> <p>Thank U very much! :)</p>