How to fix a 404 File Not Found causing a 302 redirect

Posted Apr 19, 2010

A few weeks ago, one of our consultants told us that when a file not found was issued on our servers, it was reporting a 302 redirect.

To test it, I entered a bogus page for our website in the browser
http://www.mysite.com/bogus.cfm

Looking at the Apache access log, I was quickly able to find the line reporting this.
grep bogus.cfm virtual_log

192.168.0.x - - [19/Apr/2010:10:05:25 -0400] "GET /bogus.cfm HTTP/1.1" 302 316 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.0 (.NET CLR 3.5.30729)"

Also, using the Firefox's Web Developer tools -> Information -> View Response Headers, I saw a 302 response code.

It turned out one of our Coldfusion scripts was doing a redirect using cflocation. I changed it to CFHEADER to issue the 404 status code and then another cfheader to perform the redirect.


After having the consultant review the fix, he came back and said he was still seeing the problem. He never actually gave me the example he was using the first time, so when I asked him to send me one, it turned out he wasn't accessing a file with an extension, but what could have been a directory.

http://www.mysite.com/bogus

I was able to recreate the problem, but was somewhat perplexed as to what caused it. After digging around a bit, I checked an .htaccess file to find our ErrorDocument was specified in it. Not really knowing what was wrong, I decided to try removing the domain part of the url to make it relative. So

ErrorDocument 404 http://www.mysite.com/NotFound.cfm
became
ErrorDocument 404 /NotFound.cfm

After checking the Apache access log, I no longer saw 302 and only saw 404. I can only guess it was assuming that it had to redirect to another website, so issued the 302 to www.mysite.com, not caring that it was already on that site. Changing it to a relative location made it not have to explicitly go to that URL and not having to issue the extra 302 status code.

192.168.0.x - - [19/Apr/2010:10:01:38 -0400] "GET /bogus HTTP/1.1" 404 36637 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.0 (.NET CLR 3.5.30729)"

I sent this out to our consultant for review again and hope to get a positive response.

Discussions

Comments are currently turned off

Latest Discussions

  • Carlos: Thank you!
    May 16, 2014 | Replies (0)
  • Jessica: Great info, thanks!
    May 15, 2014 | Replies (1)
  • Walter: Thanks, you totally saved me a bunch of searching around just now. I was setting up a percona xtradb...
    Feb 25, 2014 | Replies (0)
  • Avi: I've found the reason of the problem in my case. It's a bug as described here :http://bugs.mysql.com/bug.php?id=68892Shortly:...
    Dec 12, 2013 | Replies (0)
  • Avi: I've also met that behavior twice on 5.6.12 slaves. However, i didn't find the root cause of that....
    Dec 12, 2013 | Replies (0)