Tengine rewrite rule not working – common troubleshooting
2026-09-29
AdSense Slot
Rewrite rules are powerful, but small syntax mistakes cause redirect failure.
Common mistakes
- Wrong regex pattern
- Location block matching priority conflict
- Missing flag such as last, break, redirect, permanent
- Rule order error: earlier rule matches first
Example rewrite rule
rewrite ^/oldpage$ /newpage permanent;
permanent = 301 redirect.
Debug rewrite
Enable rewrite log for diagnosis:
rewrite_log on;
error_log /usr/local/tengine/logs/error.log notice;
Test config before reload:
nginx -t
Important rule
Rewrite statement order matters. Place more specific rules before generic catch-all rules.
Summary
Always test rewrite syntax and use rewrite_log for diagnosis. Location matching priority is the most hidden root cause.
AdSense Slot