title: NGINX redirect index.php UNLESS url contains /admin/
body: <p>I'm trying to remove index.php from the URL without breaking the Magento admin panel.  We're attempting to reduce SEO "duplicate content", so we are looking to do a 301 redirect if the url contains index.php... unless it is in the admin area.</p>
  
  <p>Examples:</p>
  
  <p>(domain)/index.php -> redirect to (domain)</p>
  
  <p>(domain)/index.php/category-one/ -> (domain)/category-one/</p>
  
  <p>(domain)/index.php/admin/report -> DO NOT REDIRECT</p>
  
  <p>I have this working except the /admin/ bit</p>
  
  <pre><code>if ($request_uri ~ .*.index\.php(.*)) {
      return 301 $1;  
      }
  </code></pre>
  
  <p>NGINX does not allow for nested <code>IF</code> statements.</p>
  
  <p>Any assistance is greatly appreciated.  Thank you</p>