← All articles

HTTP redirects, 301 vs 302, and how to count every click

Updated Nov 8, 2026 · 3 min read

A redirect is a response that says "what you want is somewhere else". The server answers with a status in the 3xx range and a Location header holding the new URL, and the browser makes a second request to that address on its own. The status code tells the browser two things. Is the move permanent, and can it reuse the answer next time without asking?

GET /x7Kp2Qa HTTP/1.1
Host: sho.rt

HTTP/1.1 302 Found
Location: https://example.com/spring-sale?utm_source=email
Cache-Control: private, no-store

The five statuses that matter

StatusMeaningCached by default?Keeps the method?
301 Moved PermanentlyThe resource has a new home for goodYesNot guaranteed (old clients turn POST into GET)
302 FoundIt is somewhere else for nowNoNot guaranteed
303 See OtherGo fetch this other thing with GETNoNo, always becomes GET
307 Temporary RedirectLike 302, but strictNoYes
308 Permanent RedirectLike 301, but strictYesYes

307 and 308 exist because 301 and 302 were historically allowed to change a POST into a GET. For plain links, which are always GET, 301 and 308 behave the same, and so do 302 and 307. 303 is the usual answer after a form submission, so that refreshing the result page does not submit the form again.

Why caching decides click counting

A permanent redirect is cacheable by default. Once a browser has seen a 301 for a short link, it may skip your server entirely on later clicks and go straight to the long URL, sometimes for as long as the cache lasts, with no expiry unless you set one. That is great for speed and terrible for analytics, because the first click is counted and the rest never reach you.

A 302 is not cached unless you add headers that allow it, so the browser asks your server on every click. That costs one extra round trip per click, and it is exactly what lets you count each one.

GET302from cacheBrowserShort linkcounted+1Long URLBrowsercached 301Short linknever askedLong URL302: every click is counted301: later clicks skip you
With a 302 every click reaches you. With a 301 the browser remembers the answer, and later clicks never do.

A cached 301 is hard to take back

Because browsers may keep a 301 indefinitely, you cannot reliably change where it points later. If a customer edits the destination of a short link, or you need to disable a link that now leads to malware, visitors with the old 301 cached keep going to the old place. With a 302 the next click picks up the change immediately. For anything whose destination might change, permanent redirects are a promise you may not be able to keep.

Search engines

Search engines treat a 301 or 308 as a signal to replace the old URL with the new one in their index and carry its ranking over. A 302 or 307 tells them the old URL is still the real address. That is the right choice when a site really moves; for a short link it rarely matters, since the short URL is not what you want ranked anyway.

Redirects that are not 3xx

  • <meta http-equiv="refresh"> in an HTML page makes the browser download and parse the page first, so it is slower, and many link-preview bots never follow it.
  • A JavaScript redirect (window.location = ...) is slower still, needs scripts enabled, and invisible to crawlers and previewers that do not run JS.
  • A 404 or 410: says there is nothing here. Use 410 Gone for a short link you deliberately disabled.

Counting clicks without slowing the redirect

  1. Look up the code (cache first, then database).
  2. Send the 302 straight away.
  3. Push a small click event (code, time, referrer, country) onto a queue instead of writing a counter row inline.
  4. Let a background worker batch events from the queue into your analytics store.

The visitor waits only for the lookup, and a burst of clicks becomes a burst of cheap queue appends rather than a burst of database writes on the same hot row.

GET302eventBrowserShort linkanswers 302Long URLClick queueone per clickCounteradds up in batches
The redirect returns at once. The click goes on a queue and is counted a moment later.