Skip to content

Redirect

Easy — everyone uses thisNetworking

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.