Forum Moderators: phranque
I have an example where I am automatically being redirected with a 301 response when I would ideally like the request to fail. I will outline the example and I am pretty sure someone will be able to provide a quick fix.
From [url]http://www.example.org.uk/DownloadHMusicCentre.html[/url] there are two links I have created - one to a .JPG file named "Pat Smith (1).jpg" and another to another JPG file named "Pat Smith (2).jpg". The (1) file exists on the server, the (2) does not.
If I select the (1) link, I am presented with the image that exists on the server.
If I select the (2) link, I am presented with the same image.
I have checked with HTTPLook, and I am getting a "301 Moved Permanently" response from the second request for the file that does not exist, and it is auto-redirecting me to the first file.
As you can imagine, when my program is trying to download specific assets from my site, it will be frustrating if it keeps suggesting what it thinks should be download without telling me it does not exist. I use the following code to download files - I am sure that it used to raise an exception if the file did not exist - now it just downloads whatever it is pointed to:
function DownloadFileFromURL ( const RemoteURL,
LocalFile : TFileName
) : Boolean;
begin
Result := True;
with TDownloadURL.Create (Nil) do
try
URL := RemoteURL;
Filename := LocalFile;
try
ExecuteTarget (Nil);
except
Result := False;
end;
finally
Free;
Application.ProcessMessages;
end;
end;
I figured that this might be something to do with mod_rewrite, so I tried to create myself an .htaccess file in the "www.example.org.uk/downloads" and "www.example.org.uk/downloads/ArtistImages" folders, with the single line "RewriteEngine Off" in it, but that didn't change the results from clicking the links I mention above. Although I don't know if the changes would kick-in automatically, or after a recycle of the HTTP Server - apologies for my lack of understanding on this.
My hoster's support has suggested I write extra code to check for the existence of the file before download. I fully accept that I might have to do this - and maybe that I should anyway - but I'd like to understand whether there is a server side setting that I can change so that requests for files that do not exist are not auto-suggested by the HTTP Server, i.e. stop 301s and leave them as 404s.
Any pointers appreciated.
[edited by: jdMorgan at 4:15 pm (utc) on Aug. 28, 2006]
[edit reason]
[1][edit reason] No URLs, please. See Terms of Service. [/edit] [/edit][/1]
Options -MultiViews
mod_rewrite won't change your URLs or 'interfere' with URL-to-filename translation unless you explicit write and install code to do so. However, content negotiation --if enabled by default-- will look for a 'best match' for any file not found.
Jim