In my website, I’ve got a download page. When the user clicks on the download button, they arrive on a “thank you for downloading” page. After 2 seconds, this page redirects to the actual physical file.
So it goes a bit like that:
Download page: http://example.com/download
User clicks on “Download”: http://example.com/download/getit
After 2 seconds, page redirects to: http://example.com/uploads/files/file_to_download_v2.1.zip
Currently, when I redirect to the downloadable file, I use a HTTP 301 code (Moved Permanently). However I don’t think this is the right code since, according to the standard:
The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. […] This response is cacheable unless indicated otherwise.
However, the page “download/getit” has not been assigned a new URI, it’s just redirecting to a different resource, but its own URI hasn’t changed. Also the response should not be cached since the file to download might change when a new version is released.
So what would be the right HTTP code in that case?
If you return HTTP code, the page redirects immediately, whether you use 301 (Moved Permanently) or 302 (Found) (otherwise perfectly appropriate for your usecase). If you want to redirect after 2 seconds, you need to use one of:
RefreshHTTP headerThe same in HTML meta-equiv in the page content:
JavaScript, but that may not work for everybody, so I’d avoid that.