title: Nginx - rewrite or internal redirection cycle
body: <p>Im using nginx with a very simple configuration, it works for all php sites in the subdirs of /usr/share/nginx/www/.</p>
  
  <p>But now id like to make a new project in a subdirectory with rewrite rules.
  So i decide to make a .conf for this beside the default.
  But the rewriting is not working cause of the error "rewrite or internal redirection cycle".</p>
  
  <p>default</p>
  
  <pre><code>server {
      listen 80 default_server;
      # listen [::]:80 default_server ipv6only=on;
  
      root /usr/share/nginx/www;
      index index.php index.html index.htm;
  
      # Make site accessible from http://localhost/
      server_name localhost;
  
      location / {
              # First attempt to serve request as file, then
              # as directory, then fall back to displaying a 404.
              try_files $uri $uri/ /index.html;
              # Uncomment to enable naxsi on this location
              # include /etc/nginx/naxsi.rules
      }
  
      location /doc/ {
              alias /usr/share/doc/;
              autoindex on;
              allow 127.0.0.1;
              allow ::1;
              deny all;
      }
  
      location ~ \.php$ {
              try_files $uri =404;
              # fastcgi_split_path_info ^(.+\.php)(/.+)$;
              # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  
              # With php5-cgi alone:
              # fastcgi_pass 127.0.0.1:9000;
              # With php5-fpm:
              fastcgi_pass unix:/var/run/php5-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
              fastcgi_intercept_errors on;
      }
  
      location ~ /\. {
              access_log off;
              log_not_found off;
              deny all;
      }
  }
  </code></pre>
  
  <p>newproject.conf</p>
  
  <pre><code># nginx configuration
  autoindex off;
  
  location /newproject/ {
      if (!-e $request_filename) {
              rewrite ^/newproject/(.+)$ /newproject/index.php?url=$1 break;
      }
  }
  </code></pre>