# rewrite or internal redirection cycle while processing

- **ID:** `nginx/rewrite-or-internal-redirection-cycle`
- **Domain:** nginx
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A rewrite rule or try_files directive causes an infinite loop because the rewritten URI matches the same location block repeatedly.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx 1.18.0 | active | — | — |
| nginx 1.20.2 | active | — | — |
| nginx 1.22.1 | active | — | — |
| nginx 1.24.0 | active | — | — |
| nginx 1.25.3 | active | — | — |

## Workarounds

1. **Add a break flag to the rewrite rule: rewrite ^/old/(.*)$ /new/$1 break;** (85% success)
   ```
   Add a break flag to the rewrite rule: rewrite ^/old/(.*)$ /new/$1 break;
   ```
2. **Use a separate location for the target URI to avoid recursion: location /new/ { ... }** (90% success)
   ```
   Use a separate location for the target URI to avoid recursion: location /new/ { ... }
   ```
3. **Replace rewrite with try_files and a named location: try_files $uri @fallback; location @fallback { ... }** (80% success)
   ```
   Replace rewrite with try_files and a named location: try_files $uri @fallback; location @fallback { ... }
   ```

## Dead Ends

- **** — Logging doesn't break the cycle; it only helps debug. (90% fail)
- **** — This prevents external access but may still cycle internally if rewrite triggers same location. (70% fail)
- **** — Timeouts don't affect rewrite loops; they are unrelated. (95% fail)
