Understanding Next.js Rewrites — DeepSeek Blog | Neura Market
    Neura MarketNeura Market/DeepSeek
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityDeepSeekDeepSeek
    CoPilotCoPilotStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsBlogVideosGuidesCoursesCommunityTrendingGenerate
    DeepSeekBlogUnderstanding Next.js Rewrites
    Back to Blog
    Understanding Next.js Rewrites
    architecture

    Understanding Next.js Rewrites

    Emeruche Ikenna February 26, 2026
    0 views

    Most people use Next.js very superficially. Routing, SSR, maybe API routes — and that’s it. But...

    ![cover image](https://ofxqeonyelozjixehdyo.supabase.co/storage/v1/object/public/images/user_2wtUuRPT5LK3kNVkguDKHD90vPe/09548a08-e6b0-48fb-98bf-b71db8cb7c08-png.png) Most people use Next.js very superficially. Routing, SSR, maybe API routes — and that’s it. But Next.js is not just a React framework; it’s a routing, request-handling, and application architecture layer. Many of its most powerful features live outside components and never touch JSX. One of those features is rewrites. Today, we’re talking about rewrites — what they are, how they work, and why they matter. What is a Rewrite in Next.js? ----------------------------- A rewrite allows you to map an incoming request path to a different destination without changing the URL in the browser. The user requests one URL. Your application serves content from another. The browser never knows. This is fundamentally different from redirects. Redirects tell the browser to make a new request. Rewrites happen entirely inside Next.js. **Basic Rewrite Example** ------------------------- Rewrites are defined in `next.config.js` ``` module.exports = { async rewrites() { return [ { source: '/blog/:slug', destination: '/content/posts/:slug', }, ] }, } ``` What happens here? A user visits: `/blog/nextjs-rewrites` Next.js internally serves: `/content/posts/nextjs-rewrites` The browser URL remains `/blog/nextjs-rewrites` No redirect. No reload. No visible change. **Why Rewrites Matter Architecturally** --------------------------------------- URLs are a public contract. Once users, crawlers, or external systems depend on a URL, changing it becomes expensive. Rewrites let you preserve that contract while refactoring everything underneath. This means: * you can change folder structures freely * you can reorganize routes without breaking links * you can evolve your app incrementally **API Proxying With Rewrites** ------------------------------ One of the most practical uses of rewrites is API proxying. ``` module.exports = { async rewrites() { return [ { source: '/api/:path*', destination: 'https://external-service.com/:path*', }, ] }, } ``` Now the frontend calls `/api/users` but the request is actually sent to `https://external-service.com/users` Why this is powerful: * avoids CORS issues * keeps API keys server-side * creates a single API surface for the frontend * allows backend services to change without frontend changes From the client’s perspective, everything lives under `/api` **Rewrites vs Redirects (Critical Difference)** ----------------------------------------------- Redirects: * change the browser URL * trigger a second request * are visible to the user * affect SEO Rewrites: * keep the original URL * resolve internally * are invisible to the user * do not trigger navigation If redirects are navigation tools, rewrites are infrastructure tools. **Rewrites and the Request Lifecycle** -------------------------------------- Rewrites run before routing. This means: * Next.js evaluates rewrites first * then resolves the final route * then executes page or API logic Because of this: * req.url may not reflect the final destination * middleware logic must be tested carefully * assumptions about paths can break if rewrites are ignored This is one of the few “gotchas” with rewrites — they are powerful precisely because they’re invisible. **Conditional Rewrites** ------------------------ Rewrites can also be conditional. Example based on headers: ``` { source: '/dashboard', has: [ { type: 'header', key: 'x-admin', value: 'true', }, ], destination: '/admin/dashboard', } ``` Same URL. Different destination. Different behavior. This enables: * role-based routing * multi-tenant applications * internal feature flags * environment-based routing **Why Rewrites Are Underrated** ------------------------------- Rewrites don’t live in components. They don’t affect UI. They don’t announce themselves. But they: * decouple URLs from implementation * enable safe refactors * turn Next.js into a lightweight gateway * push routing decisions closer to infrastructure Once you understand rewrites, you stop thinking of URLs as file paths and start treating them as interfaces. And that’s a shift that changes how you design applications. **Final Thought** ----------------- Rewrites are not about convenience. They’re about control. They allow Next.js apps to grow, migrate, and evolve without breaking users or clients. If you’re building anything beyond a small project, rewrites are not optional — they’re foundational. Most people never go past the surface of Next.js. Rewrites are one of the first features that show you how deep it actually goes.

    Tags

    architecturejavascriptnextjsreact

    Comments

    More Blog

    View all
    How I'm using ASTs and Gemini to solve the "Codebase Onboarding" problem 🧠ai

    How I'm using ASTs and Gemini to solve the "Codebase Onboarding" problem 🧠

    Hi everyone! 👋 I’m Tara, a Senior Software Engineer and Consultant. Over the years, I've jumped...

    T
    tworrell
    Local AI Will Save Us All (The Math Says So, Trust Me)ai

    Local AI Will Save Us All (The Math Says So, Trust Me)

    Every few weeks a take goes viral in tech circles making the case for ditching cloud AI and running...

    S
    Sebastian Schürmann
    Lost in the AI Hype, I Started Smallai

    Lost in the AI Hype, I Started Small

    And it helped me get back into tech without drowning TL;DR at the end Coming back to...

    R
    Rohini Gaonkar
    Building a Replay-Tested Interactive Brokers Client in Gogo

    Building a Replay-Tested Interactive Brokers Client in Go

    I wanted an IBKR library that felt like Go and had testing I could trust. So I wrote one.

    T
    Thomas Marcelis
    Playwright in Pictures: Fully Parallel Modeplaywright

    Playwright in Pictures: Fully Parallel Mode

    Playwright’s fullyParallel mode is often treated as a simple performance switch. In practice, it...

    V
    Vitaliy Potapov
    Designing a CLI for Both Humans and Agentscli

    Designing a CLI for Both Humans and Agents

    Learn how Alpic designed its CLI for both human developers and AI agents — covering tradeoffs like polling, context windows, interactivity, and statelessness.

    J
    Julien Vallini

    Stay up to date

    Get the latest DeepSeek prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for DeepSeek and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.