title: Same regex behaving differently in Apache and Nginx
body: <p>I'm trying to covert <a href="https://perishablepress.com/5g-blacklist-2013/" rel="nofollow noreferrer">5G Blacklist</a> to from Apache(.htaccess) to Nginx(.conf). There is a line in .htaccess that is causing problem:</p>
  
  <pre><code>&lt;IfModule mod_alias.c&gt;  
      RedirectMatch 403 (\,|\)\+|/\,/|\{0\}|\(/\(|\.\.\.|\+\+\+|\||\\\"\\\")  
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>I have converted it to .conf as follows:  </p>
  
  <p><strong>Code included in http block</strong> </p>
  
  <pre><code>map $request_uri $bad_uri {  
      default 0;  
      "~*(\,|\)\+|/\,/|\{0\}|\(/\(|\.\.\.|\+\+\+|\||\\\"\\\")" 1;  
  }  
  </code></pre>
  
  <p><strong>Code included in server block</strong>  </p>
  
  <pre><code>if ($bad_uri) {  
      return 403;  
  }  
  </code></pre>
  
  <p>As far as I know both Apache and Nginx use <a href="http://perldoc.perl.org/perlre.html" rel="nofollow noreferrer">perl regex</a> so no change should be required when converting from former to the latter. However, following URI is giving 403 on Nginx but working fine on Apache:  </p>
  
  <blockquote>
    <p><s>www.example.com/some,url,with,commas</s><br>
    www.example.com/?q=some,url,with,commas</p>
  </blockquote>