We’re working on a URL shortener project in PHP. We’re using 301 HTTP redirection and naturally track our links visits. but there is something strange :
After we shorten a URL and go through it by a browser, only the first visit is tracked, and it seems that no other request is sent to our server and it directly goes to the destination URL.(I think this is a browser cache after one try). But :
When trying with a similar service like bitly , it has different treat. some of the same requests on the same browsers are tracked in bitly visit tracking (In fact more than one of them, and I don’t understand why, I don’t see any logic) while they also use 301 redirection.(at left bottom of browser window sometimes writes “waiting for bit.ly…” and sometimes not , in fact randomly).
Are any tricks included here? What this different treat happens?
Read the HTTP specification. A
301response tells the browser that the requested resource has permanantly moved to the new URL that is being redirected to, and should not use the original URL anymore:For what you are attempting, try using
302,303, or307instead..
.