next.config.js / .mjs Simulator
next.config.js Redirects Tester & Rewrites Simulator
Test next.config.js redirects(), next.config.mjs rewrites (beforeFiles/afterFiles/fallback), permanent 308/307 codes, basePath, and regex params locally—zero eval().
https://example.com/articles/2026/edge-routing?utm_source=hn
Evaluation Trace
Hop-by-Hop & Exact Rule Priority Breakdown
Rule #1 (redirect) /old-post
Skipped: path "/blog/2026/edge-routing" did not match "/old-post"
Rule #2 (redirect) /blog/:slug*
Matched Rule #2: 308 redirect -> https://example.com/articles/2026/edge-routing?utm_source=hn
Next.js Routing Engine
Validate next.config.js Phases, Regex Params & basePath Before Build
Debug Next.js routing in browser memory using a safe next.config.js redirects tester. Trace phase ordering, regex params, and basePath prefixes before running next build.
Zero-eval() Safe JS Parser
Extracts module.exports, export default, comments, and TypeScript NextConfig snippets statically without executing code.
Phased Rewrites Support
Evaluates simple rewrite arrays alongside { beforeFiles, afterFiles, fallback } objects in exact Next.js phase order.
basePath & trailingSlash Controls
Auto-reads basePath and trailingSlash from your config with Request Context overrides for subpath testing.
Phased Routing & AST Parsing
Simulating Next.js Phases, Regex Captures & basePath Locally
Paste module.exports or export default configs straight from your repo. Our next.config.mjs rewrites simulator preserves exact phase order and checks basePath overrides.
Zero-eval() Static Parser
Phased Rewrites & Regex Testing
The nextjs redirects regex tester compiles :id(\d+) constraints and phased { beforeFiles, afterFiles, fallback } objects while flagging shadowed rules per phase.
Compare with our vercel.json redirects tester online, Cloudflare Pages _redirects tester, or redirects tester online.
async rewrites() {
return {
beforeFiles: [{ source: '/app/:path*', destination: '/beta/:path*' }],
afterFiles: [{ source: '/api/v1/users/:id(\\d+)', destination: '/api/v2/members?id=:id' }],
};
}Status & Subpath Context
Permanent 308 Checker & basePath: false
Every Next.js redirect requires permanent: true (308), permanent: false (307), or statusCode. The nextjs permanent 308 redirect checker reads basePath/trailingSlash and honors basePath: false opt-outs.
Migrating static JSON rules? Try the vercel.json to Cloudflare redirects converter.
{
source: '/health',
destination: '/api/ok',
permanent: false, // 307 Temporary Redirect
basePath: false, // Bypass global basePath
}Syntax Reference
Patterns, Status Codes & Matching Semantics
| Pattern / Syntax | Behavior | Example |
|---|---|---|
| permanent: true | Issues HTTP 308 Permanent Redirect (method-preserving) | { source: "/old", destination: "/new", permanent: true } |
| permanent: false | Issues HTTP 307 Temporary Redirect (method-preserving) | { source: "/beta", destination: "/app", permanent: false } |
| beforeFiles / afterFiles / fallback | Controls rewrite execution relative to static files and dynamic routes | return { beforeFiles: [...], afterFiles: [...] } |
| basePath: false | Opts a rule out of Next.js global basePath prefixing | { source: "/health", destination: "/api/ok", basePath: false } |
FAQ
Common Questions & Edge Cases
In what order does Next.js evaluate redirects and phased rewrites?
Next.js runs redirects() first, then beforeFiles rewrites, filesystem pages/public, afterFiles rewrites, dynamic routes, and finally fallback rewrites.
Is next.config.js or next.config.mjs executed with eval()?
No. This next.config.js redirects tester uses a safe static tokenizer and recursive-descent parser without running arbitrary JS.
Why does Next.js use 308 and 307 instead of 301 and 302?
308 and 307 preserve HTTP methods like POST. Use this nextjs permanent 308 redirect checker to verify permanent: true (308), false (307), or custom statusCode.
What happens with dynamic Node imports or array spreads?
Static arrays parse cleanly; dynamic expressions or spreads trigger line-level warnings showing which dynamic pieces were skipped.
More Tools on RedirectsTester
Dedicated Format Simulators & Converters
vercel.json Tester
Test framework-agnostic Vercel redirects and rewrites JSON.
CONVERTERVercel → Cloudflare
Migrate vercel.json redirect definitions to Cloudflare Pages _redirects.
CLOUDFLARECloudflare _redirects
Simulate Cloudflare Pages splat rules, placeholders, and rule limits.
ALL-IN-ONEUniversal Simulator
Switch instantly between vercel.json, next.config.js, and _redirects.