rewrite or internal redirection cycle Nginx / Apache Origin: Edge & web server OSI layer 7 · Application Last updated 5 Nov 2026

Nginx: [error] rewrite or internal redirection cycle while internally redirecting to "/index.php" (500 Internal Server Error)

Nginx kept internally redirecting (more than 10 times), typically from a try_files or rewrite that points back to itself.

Exact message you may see rewrite or internal redirection cycle while internally redirecting to "/index.php"[error] rewrite or internal redirection cycle while internally redirecting to500 Internal Server Error rewrite or internal redirection cyclerewrite or internal redirection cycle while processingnginx internal redirection cycle index.html
Seen on: Nginx PHP Linux

Meaning

Common with try_files $uri $uri/ /index.php; when /index.php doesn't exist at the configured root, or an index directive loop. Check root path, that the file exists, and the order of location blocks (location ~ \.php$ must handle /index.php).

Common causes

  • /index.php missing under the configured root
  • root points to the wrong directory
  • try_files fallback to a non-existing URI
  • Rewrite rule that matches its own output
  • Location for PHP not defined

⚡ Quick fix

  1. Verify root and that index.php exists
  2. Fix fallback: try_files $uri $uri/ /index.php?$query_string; with a working PHP location
  3. Avoid rewriting to a path matched by the same rule

Detailed fix by platform

Linux

  1. sudo nginx -T | grep -nE "root|try_files|index"; ls -l /var/www/app/public/index.php

How to diagnose

  1. File — index.php exists?
  2. Root — Correct path?
  3. Location — PHP block?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Edge & web server. Errors that are often confused with or caused by this one (click to open):

404 on all routes except home (public folder / .htaccess) — Laravel on shared hosting: homepage works but every other route returns 404 Not Found (Laravel)404 on all routes exc…499 Client Closed Request / client prematurely closed connection — Nginx: [info] client prematurely closed connection while reading response header from upstream / access log status 499 (Nginx / Apache)499 Client Closed Req…AH00124: Request exceeded the limit of 10 internal redirects — Apache: AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary (Nginx / Apache)AH00124: Request exce…directory index of "/var/www/" is forbidden — Nginx: [error] directory index of "/var/www/html/" is forbidden (403 Forbidden) (Nginx / Apache)directory index of "/…ModSecurity: Access denied with code 403 — Nginx/Apache: ModSecurity: Access denied with code 403 (phase 2). Matched "Operator GE matched 5 at TX:anomaly_score" (Nginx / Apache)ModSecurity: Access d…nginx: client intended to send too large body — Nginx: [error] client intended to send too large body: 5242880 bytes (413 Request Entity Too Large) (Nginx / Apache)nginx: client intende…Primary script unknown — FastCGI sent in stderr: "Primary script unknown" (PHP)Primary script unknownrewrite o…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.