Redirects in a URL Shortener: 301 vs 302 vs 307 and Why It Matters

Choose the right redirect status for a URL shortener. How 301, 302, 307 and 308 affect browser caching, analytics accuracy, SEO and server load.

Published November 27, 2026

The redirect is the product. Every click on a short link ends in an HTTP response with a Location header, and the status code you choose quietly decides whether you can count clicks, how much traffic your servers absorb, and how search engines treat the destination. It is a one-line decision with big consequences.

The concept

A 301 Moved Permanently tells browsers and crawlers that the mapping will never change. Browsers cache it aggressively, often indefinitely. The next time the same user clicks the same short link, the browser redirects locally without contacting your server at all. That saves load, but you lose the click in your analytics and cannot change or disable the link for that user.

A 302 Found (temporary) tells clients not to cache the redirect unless cache headers say otherwise. Every click reaches your server, so every click can be counted, links can be edited or expired, and abusive links can be disabled instantly. The cost is higher server traffic. 307 and 308 are the modern equivalents of 302 and 301 that guarantee the HTTP method and body are preserved, which matters for APIs but not for normal link clicks.

Redirect codes compared

StatusMeaningBrowser cachingAnalyticsUse when
301Moved PermanentlyCached aggressivelyRepeat clicks lostFixed links, minimal server load
302Found (temporary)Not cached by defaultEvery click countedMost shorteners
307Temporary, method keptNot cached by defaultEvery click countedRedirecting POST/API requests
308Permanent, method keptCachedRepeat clicks lostPermanent API endpoint moves

301: the browser remembers

BrowserShortenerDestinationGET /aZ3kP9q301 Location: …GET destinationlater click: cached 301straight to destination
With 301, repeat clicks never reach the shortener.

302: every click counted

BrowserShortenerDestinationGET /aZ3kP9q302 + Cache-Control: no-storeGET destinationlater click: asks again302 (click counted)
With 302, every click is visible to the shortener.

What about SEO?

Search engines generally pass ranking signals through both permanent and temporary redirects today, and they treat long-standing temporary redirects much like permanent ones. For a shortener the bigger SEO question is that destination pages should declare their own canonical URL; the short link is not meant to be indexed itself. Add X-Robots-Tag: noindex to redirect responses if you want to be explicit.

Practical examples

A minimal redirect handler (Express)

Look up the code, set no-store, and redirect with 302.

app.get('/:code', async (req, res) => {
  const link = await links.get(req.params.code)       // cache, then DB
  if (!link) return res.status(404).send('Not found')
  if (link.expiresAt && link.expiresAt < Date.now()) return res.status(410).send('Link expired')
  res.set('Cache-Control', 'private, no-store')
  res.set('X-Robots-Tag', 'noindex')
  res.redirect(302, link.longUrl)
  analytics.enqueue({ code: link.code, ts: Date.now(), ua: req.get('user-agent'), ref: req.get('referer') })
})

Cache at the CDN but not in browsers

A compromise: the CDN absorbs load for a short time while browsers always revalidate.

HTTP/1.1 302 Found
Location: https://example.com/landing
Cache-Control: private, no-store
CDN-Cache-Control: max-age=60

Check what a short link returns

curl -I shows the status and Location without following.

curl -sI https://sho.rt/aZ3kP9q | grep -iE '^(HTTP|location|cache-control)'

Common mistakes

  • Using 301 and then trying to change or disable a link: browsers that cached it will ignore the change.
  • Forgetting Cache-Control and letting intermediaries cache a 302 anyway.
  • Doing the analytics write synchronously before sending the redirect, adding latency to every click.
  • Returning 200 with a JavaScript or meta-refresh redirect, which is slower and breaks some clients and previews.

Key takeaways

  • 301 saves server load but hides repeat clicks and makes links effectively permanent.
  • 302 (or 307) keeps every click visible and links editable; most shorteners use it.
  • Send the redirect first and record analytics asynchronously.
  • Set explicit Cache-Control headers so intermediaries behave predictably.

FAQ

Do link previews (Slack, X, WhatsApp) count as clicks?

They fetch the link with bot user agents. Filter known preview bots out of analytics or count them separately.

Can I switch from 301 to 302 later?

For new visitors, yes. Users whose browsers cached the 301 keep using the old mapping until their cache is cleared.

Should redirects go over HTTPS?

Yes. An HTTP short link can be tampered with by anyone on the network path; serve short links over HTTPS with HSTS.

More Architecture articles