Reputation: 97
I have a file which contains a version number in the filename and is updated almost every month.(The version number is necessary for other software which needs that to work properly.)
To make published links with an old version number also workable, for user convenience, I wrote a php script which does a redirect with a 301 header, and provides the latest file with the current version number for download.
Now I found in the log file that old links with an old version number a kept in the index of search engines, and it's more and more growing that they aks for old files(urls), and even with the 301 redirect they do not update the stored links and ask for the old files over and over again.
After reading a while I found that the only way to get them out of the index is to send a 404 or 410 header, but it seems on the other hand, that this doesn't let me send a file with that header.
So the question is do you see any chance how I can send a 404 or 410 header to get old links away from search engine indexes, and at the same time provide the latest file for download to have old links still working for user comfort?
Upvotes: 0
Views: 92
Reputation: 1826
You can use a combination of the meta http-eqiv attribute and JavaScript to allow requests from browsers to complete. This method will not work for wget
, curl
or other such automated programs.
<!doctype html>
<html>
<head>
<title>File not found</title>
<meta charset="utf-8"/>
<meta http-equiv="refresh" content="5;URL=http://somedomain.tld/file_v1.txt"/>
</head>
<body>
<p>The requested resource does not exist. However, an older version of the file was found and will begin downloading in <span id="countdown">5</span> seconds.</p>
<p>Please <a href="http://somedomain.tld/file_v1.txt">click here</a> if the download does not begin or you no longer wish to wait.</p>
<script>
// you can get #countdown and using setInterval decrease the seconds to enhance the user experience
// additionally, you can use `window.location.href = "http://somedomain.tld/file_v1.txt";` at 0 seconds
// incase the user has meta redirects disabled
</script>
</body>
</html>
Upvotes: 1