2

Serving a Permanent 301 redirect or a Temporary 302 redirect in Django is very straightforward using the redirect shortcut (which in turn just uses HttpResponsePermanentRedirect or HttpResponseRedirect)

I need to count how many times a redirect was used, but if I use 301, my view is only hit on the first request. Browsers presumably cache the new URL, because successive requests don't hit my view.

And yet I can see that many URL shortening services (http://searchengineland.com/analysis-which-url-shortening-service-should-you-use-17204) do use 301 AND count hits.

How do they do this? I can see they write cookies, but I don't understand what this buys you?

Jason Blum
  • 172
  • 5
  • 2
    Are you sure that the services are not just tracking the initial request? – Alasdair Apr 01 '16 at 13:41
  • [This post on SO](http://stackoverflow.com/questions/9130422/how-long-do-browsers-cache-http-301s) suggests to use `Cache-Control` header. Bit.ly sets `Cache-Control` header to private with `60` as expriation time. – v1k45 Apr 01 '16 at 13:48

1 Answers1

0

@Alisdair is correct. When I created a short url in various services and hit refresh, I saw the hit count increase, but did not consider that it was not actually me, but a bot watching newly created short URLs :) Yes, 301 Permanent redirect allws them to track only the initial request.

Jason Blum
  • 172
  • 5