Rewrite vs redirect

A redirect sends the browser elsewhere and the URL changes. A rewrite quietly serves other content while the URL stays put.

keep the URL but show something elsedifference between rewrite and redirect301 vs proxythe address bar changes and I don't want it tosend the browser somewhere elseproxy a path to another siteredirect vs rewrite seourl masking

See it

Live demo coming soon

What it is

A redirect answers with a status code and a Location header, so the browser makes a second request and the address bar changes. 301 and 308 are permanent and act as a strong canonicalization signal, so search engines consolidate ranking on the new URL. 302 and 307 are temporary and generally leave the original URL as the canonical one, though a temporary redirect left in place for months can end up treated like a permanent one. A rewrite is invisible: one request, the server maps the path to different content behind the scenes, and the URL the visitor sees never moves.

Redirect when the canonical address genuinely changed: renamed pages, www to apex, http to https, retired campaign URLs. Rewrite when the address is the product and the source is an implementation detail: '/blog' served from a separate CMS deployment, '/docs' proxied from another origin, a customer subdomain mapped to '/tenants/acme'.

Gotchas worth the scar tissue. A 301 gets cached hard by browsers and is close to impossible to take back, so use 307 while you are still experimenting. Rewrites can leave the same page reachable at two URLs, which splits SEO signals unless you set a canonical tag. And relative asset paths often break behind a rewrite, because the browser resolves them against the URL it can see, not the one you rewrote to.

Ask AI for it

Set up routing rules for this site: permanently redirect (308) '/pricing-2023' to '/pricing', redirect the www hostname to the apex domain, and use temporary (307) redirects for anything still being tested. Then rewrite '/blog' and '/blog/:slug' to the external CMS origin so the URL stays on my domain. Add a canonical link tag on the rewritten pages, make asset URLs absolute so they survive the rewrite, and show me the finished config with a comment on each rule saying why it is a rewrite or a redirect.

You might have meant

edge middlewarereverse proxyorigin serverwildcard domain subdomain routingedge function