-
- 258 Posts
I really like the feature that allows you to redirect a user to a specified page when an error happens. The problem though is that this error does not get recorded in my Apache logs as a 404 error. It simply shows up as a 302 Redirect. This basically makes my Apache error log worthless.
Am I missing something obvious in my set up? Or is there a better way to keep track of errors in my site?
Thanks
It has to do with Search Engine Friendly URLs being on, but I don’t know how to reconcile them on and having Apache error logs working.
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
-
- 258 Posts
But clearly the server knows when an error happens, since it has to do the redirect. Why not solve this ploblem by having the server generate a 404 and then using Apache’s error redirection to feed th right error page? Make sense?
Actually, the server doesn’t know. This is because the rewrite rules intercept all requests for resources that don’t exist physically on the server and send them as a query string component to MODx’s index.php. Then MODx looks for the virtual resource within the MODx database, and if it is not found, MODx handles the error.
-
- 258 Posts
Which rewrite rules intercept the request? Apache’s or ModX’s? If it’s the latter, why not put some logic in ModX to generate a 404 instead of the redirect and let Apache deal with it from there?
-
- 2,204 Posts
Its done by modx parser I like that better then people seeing some 404 apache page what maybe could be done is that a extra logging is made for the pages that are being redirected in modx instead of apache logging
I think that this could be done the same as modx logs all visits.
-
- 258 Posts
So the solution is not quite so simple. The mod_rewrite rule simply punts on any file/dir name that’s not on the filesystem and hands it off to index.php. There’s not enough knowledge at this point to know whether this is a valid request or not.
But in includes/document.parser.class.inc.php, in the sendErrorPage function, we reconstruct the the original request and pass that off to our error page to deal with.
My contention is that we should not do this since we hijack Apache’s logging. Why not return a 404 at this point and use Apache’s ErrorDocument directive to do the dirty work?
Victor, I think this is a matter of preference. Again, I believe the best solution is to force the 404 error from your error page, or not use friendly aliases. I personally prefer anyone that doesn’t get one of my pages successfully be directed to a page also delivered by MODx so I can programmatically handle the issue. This gives me all sorts of options to deal with the bad requests, including email notifications, contextual error messages, and any thing else I can dream up.