Location
response headerrouting & context
The URL to go to next — the target of a redirect, or the address of a newly created resource.
With a 3xx status, Location is where the client should go next; browsers follow it automatically. With 201 Created, it points at the resource that was just created. Relative URLs are allowed and resolve against the request URL.
Syntax
Location: <url>
Defined in RFC 9110 §10.2.2 — Location.
Examples
Location: https://www.example.com/new-path
an absolute redirect target
Location: /login?next=%2Fdashboard
a relative URL, resolved against the request
Location: /api/orders/1234
with 201 Created: the new resource
Good to know
- Use 301 or 308 for permanent moves, 302 or 307 for temporary ones. 307 and 308 keep the method and body.
- Never redirect to a URL taken straight from user input — validate it against an allowlist to avoid open redirects.
- fetch follows redirects silently; check
res.redirectedandres.urlto see where you ended up.
Further reading: 301 vs 302 vs 307 vs 308 · HTTP status checker · Fixing ERR_TOO_MANY_REDIRECTS
How to set Location
res.redirect(301, "https://www.example.com/new-path");
module.exports = {
async redirects() {
return [
{ source: "/old-path", destination: "/new-path", permanent: true }, // 308
];
},
};import { redirect, permanentRedirect } from "next/navigation";
redirect("/login"); // 307
permanentRedirect("/new-path"); // 308location = /old-path {
return 301 https://www.example.com/new-path;
}Redirect 301 /old-path https://www.example.com/new-path
Check it
Fetch only the response headers and filter for Location. In the browser, it's under Response Headers in DevTools → Network.
curl -sI https://example.com/ | grep -i '^location:'
To compare response headers across many URLs at once, use the HTTP Status Checker.
Frequently asked questions
Can Location be a relative URL?
Yes. Since RFC 7231, relative references are allowed and resolved against the request URL, and every browser supports them.
Why does my redirect loop?
The target redirects back — often HTTP↔HTTPS or www↔apex rules fighting, or a proxy that terminates TLS so the app thinks every request is plain HTTP. Trace it with curl -sIL.