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().

Presets:
next.config.mjs3 rules
Try:
308 PERMANENT1 hop
< 1ms local
Resolved Destination URL

https://example.com/articles/2026/edge-routing?utm_source=hn

Evaluation Trace

Hop-by-Hop & Exact Rule Priority Breakdown

2 rule checks
Hop 1https://example.com/blog/2026/edge-routing?utm_source=hn
308 REDIRECT
→https://example.com/articles/2026/edge-routing?utm_source=hn
Captures::slug = 2026/edge-routing
SKIP

Rule #1 (redirect) /old-post

Skipped: path "/blog/2026/edge-routing" did not match "/old-post"

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 / SyntaxBehaviorExample
permanent: trueIssues HTTP 308 Permanent Redirect (method-preserving)
permanent: falseIssues HTTP 307 Temporary Redirect (method-preserving)
beforeFiles / afterFiles / fallbackControls rewrite execution relative to static files and dynamic routes
basePath: falseOpts a rule out of Next.js global basePath prefixing

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.