Redirect
ELI5 — The Vibe Check
A redirect is when a server says 'what you want isn't here, go look over there instead.' Your browser automatically follows to the new URL. It happens so fast you usually don't notice. Used for moved pages, HTTPS upgrades, and login flows.
Real Talk
An HTTP redirect is a response with a 3xx status code and a Location header pointing to a new URL. The client (browser) automatically issues a new request to the redirect URL. Types include 301 (permanent), 302 (temporary), 307, and 308.
Show Me The Code
// Express redirect examples
app.get('/old-page', (req, res) => {
res.redirect(301, '/new-page'); // Permanent
});
app.get('/login-required', (req, res) => {
res.redirect(302, '/login'); // Temporary
});
// Redirect HTTP to HTTPS
app.use((req, res, next) => {
if (!req.secure) res.redirect(301, `https://${req.hostname}${req.url}`);
else next();
});
When You'll Hear This
"Add a redirect from the old URL to the new one." / "Too many redirects in a chain will cause a browser error."
Related Terms
301 Redirect
A 301 redirect says 'this page has PERMANENTLY moved to a new address.' Browsers remember it and go straight to the new URL next time.
302 Redirect
A 302 redirect says 'this page is TEMPORARILY somewhere else — come back here later.' Browsers don't cache it and search engines don't transfer SEO juice.
Header
Headers are the metadata attached to HTTP requests and responses — information about the information.
Status Code
An HTTP status code is the server's one-line verdict on your request. 200 means 'perfect, here's what you asked for.' 404 means 'can't find it.
URL (Uniform Resource Locator)
A URL is the complete web address of something on the internet — the full 'how to get there' including the protocol, domain, path, and any query parameters...