Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have made a custom 404 error page called error_404.html

In my .htaccess I inserted:

ErrorDocument 404 /error_404.html

In order to control/correct 404 errors in my website, I would like to know which URL requests return this page.

Is there a way I can check which URL/log requests returned my error_404.html page?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You do not need a custom error document in order to monitor 404's on your site - if that is the requirement. All the information is in your server access log. The HTTP response code (ie. 404, 403, 200, etc) and the URL of the request that produced that response.

The custom error document is a nice way of serving a meaningful response to users.

You can also register your site with Google Webmaster Tools (GWT). This will produce a report of all the URLs that it attempted to crawl (ie. URLs that it could find) that produced a 404.

Bare in mind that your access log will report a lot more 404s than GWT because there are a lot of nasty bots out there looking for vulnerabilities that will try to request all sorts of URLs that might be unrelated to your site. Ignore these, or block the bots if they are persistent.

share|improve this answer
    
It was my first instinct to mention the log file, then I thought he might want something more declarative. I meant to mention the log file in my answer after finding another method, but forgot. Thanks for providing the answer which on one hand seems so obvious, but on the other, rarely looked to. It amazes me how many answers to questions are in the log file, but people fail to think in those terms. Thanks for mentioning the log file. –  closetnoc Apr 29 at 22:18
    
@closetnoc: Yeah, I would have thought the access log (or at least a reporting tool that reads this) would be the first thing to try. Although, this may not be easily accessible on some shared hosting accounts? Or maybe it just seems too cumbersome on their setup?? –  w3d Apr 29 at 22:52
    
That was part of my assumption. I cannot understand why a log file would not be available, but that may be the new way. I was a webhost in a previous life and while I parsed and split log files for customers along with a choice of two reporting engines, with so many servers and the fact that parsing a log file can be intensive, I can imagine why a webhost might avoid this. –  closetnoc Apr 29 at 23:18

This works: emulating ErrorDocuments with mod_rewrite.

ErrorDocument 404 /404.html Redirect 404 /404 RewriteCond %{ENV:REDIRECT_STATUS} !=404 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* /404 [L]

share|improve this answer
1  
Thanks for jumping in! BTW- I like your website. I read the question as how to trap what access is triggering the 404. I was kinda assuming no access to the log file. I like your solution. The reason why I chose the other is that there may be an opportunity to pass the request as a parameter and then write it to a file. The example I cited was of course not complete, but I thought it was a good jumping off point. Glad to see you here. You are a great resource and a font of knowledge! –  closetnoc May 8 at 0:32

I do not believe so. Not using ErrorDocument the way you have specified.

Here is a resource site that seems to have some answers.

http://www.askapache.com/htaccess/htaccess.html#Custom_ErrorDocuments

Scroll down and you will find this example. If it is not exactly what you want, it can be modified.

### ALTERNATATIVE TO USING ERRORDOCUMENT
# http://www.htaccesselite.com/d/htaccess-errordocument-examples-vt11.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /error.php [L]

You can also check out for more information:

http://www.askapache.com/htaccess/security-with-htaccess.html#errordocument-usage-in-htaccess

share|improve this answer
    
Just a point about that code sample... without additional code (perhaps inside error.php) it could end up simply masking the 404 and serving a 200 OK status instead - which probably isn't so good. –  w3d Apr 29 at 22:59
    
True. I made the assumption that the Apache mod_rewrite variables could be used to create parameters for the error.php file. Yes. The example does not solve his problem completely, but rather is a starting point. The second link seemed to have PHP examples that would get him further. Good point. –  closetnoc Apr 29 at 23:15
    
This however, absolutely does: emulating ErrorDocuments with mod_rewrite –  AskApache May 8 at 0:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.