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

**Code:** `rewrite or internal redirection cycle` · **Category:** Nginx / Apache · **Seen on:** Nginx, PHP, Linux

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nginx-apache/nginx-rewrite-or-internal-redirection-cycle)
