301 Moved Permanently Versus 302 Found
TradeoffMidSeniorUpdated
A URL shortener counts every click for its analytics dashboard, and owners can edit or expire a link's destination. Which status code should GET /:code return?
Short answer: 302 Found (or 307 Temporary Redirect). Browsers cache a 301 and go straight to the destination on repeat visits, so those clicks never reach your click stream and a later edit to the link never takes effect for that browser.
The Two Options
A
301 Moved Permanently
B
302 Found (or 307 Temporary Redirect)
Drill This: Your Pick First
The Better Pick
Option B
302 Found (or 307 Temporary Redirect)
Browsers cache a 301 and go straight to the destination on repeat visits, so those clicks never reach your click stream and a later edit to the link never takes effect for that browser. A 302 sends every click back through the service (or a CDN whose edge logs you collect), which keeps counts accurate and destinations editable.
When the Other One Wins
301 Moved Permanently
If links never change and you don't count clicks, a 301 saves the extra round trip on repeat visits and takes load off the redirect service.