News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Add an Apache Error Handler to SMF

Started by Deprecated, September 02, 2008, 04:15:47 AM

Previous topic - Next topic

Deprecated

Link to Mod

Obsolete.

Nathaniel

Very nice mod. :)

Downloaded and installed for SMF 2 Beta with no hitches. ;D

I had previously done this by using a host error page to redirect the user to a custom action within SMF, this makes it much easier.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

Charles Hill

You should be aware that this is totally incompatible with the Pretty URLs mod.  I just tested it on my dev site.  Had to type out the entire URL to uninstall the package.

Deprecated

#3
Readme.txt from the package:

Add an Apache Error Handler to SMF


Version: 1.0 Date: 2008-08-30
Compatibility: SMF 1.1.5, SMF 2.0 Beta 3.1 or later

This modification adds to SMF the capability to intercept all Apache errors such as 'Error 404 - Not Found' and the like, and displays an error message to your members using your familiar forum format. It also adds error entries to SMF's error log so that you can see and investigate the errors.

There is an important matter that every hosting customer should understand. Hosting services provide default error pages if the customer does not supply their own. For example, my SMF test forum domain has the word 'dog' in its domain name, I guess because I'm fond of the critters. Without my custom error page I get a default hosting service error handler that they use for parked domains. They must have sensed the word 'dog' in my domain name because they serve up a page of suggestions for other domains that might have what the site visitor is looking for. In my case the Error 404 page has suggestions for dog food, vetenarians, dog informational sites, etc. Ask yourself this question: Are you willing to take the chance that your hosting service will send your forum members to competing services including competing forums whenever there is a site error?
Features

  • Intercepts Apache errors 400-417, 500-505
  • Supplies a user message indicating error type and description
  • Logs the errors in SMF's error log including error URL
  • Provides a seamless integration between Apache error messages and SMF
  • Automatically configures your .htaccess file
Note: The modification will work only on servers with Apache installed.
Screen shot


Installation

Please back up your index.php and .htaccess files before beginning the installation. Automatic deinstallation almost always succeeds but it never harms to be prepared for the worst.

The modification automatically adds directives to your .htaccess file if one is present, or creates a new .htaccess file otherwise. Any existing .htaccess file is renamed .htaccess~ for a backup after its contents have been added to the new .htaccess file. Uninstalling the modification restores your old .htaccess file if one was present, or removes the modification's .htaccess file otherwise. If you delete the backup file the modification will attempt to remove its directives from whatever .htaccess file it finds, or does nothing to the file if the modification's directives cannot be safely removed.

The .htaccess file is installed in your board directory whether it is '/' or '/forum/' or whatever your called it. If your forum is installed in e.g. '/forum/' and you would like your SMF to handle errors from the entire domain (such as including your portal) you can copy the .htaccess file to your '/' folder. Uninstallation will not remove any copied file so you will have to manually delete it if you uninstall the modification.

Note 1: If you already have a 'RewriteEngine on' directive, the modification still adds its own. Multiple instances of the directive will harm nothing, and your directive will still be there if you uninstall the modification.

Note 2: Please understand that Error 500 Internal Server Error is internally generated by Apache when it is unable to handle a request for any reason. This occurs before your error handler can be called so it is unlikely that you will ever see an Error 500 display or log entries. It is not possible to intercept Error 500 under normal circumstances so this is not a failing of the modification.
Uninstallation

Use SMF's package installer to remove the modification.

Note: If desired, the included UpdateHtaccess.php file can be run stand-alone in your board directory to modify or demodify your .htaccess file. Use 'UpdateHtaccess.php' to install the .htaccess file changes. Use 'UpdateHtaccess.php?uninstall' to remove the .htaccess file changes. Or alternately, you can just manually edit or delete your .htaccess fie.
Support

You may get support or submit questions and comments in the modification's support thread at the SMF site.[/hr][/hr][/hr][/hr][/hr]

Deprecated

@LHVWB Thanks for the comments LH! I had been running a separate error handler script where I had done a quick hack, viewing HTML source on my forum index and cut 'n pasted enough HTML to make the top part look like SMF. I've been running custom error handler scripts on my non-forum websites for a couple years, and have found the error logs to be quite handy for debugging pesky little site inconsistencies. I have began running SMF forums only the last couple months but almost from the beginning when I realized I could hack my SMF and install any feature I was willing to take the time to code up, I realized that it was only a matter of time before I added custom error handlers, but it was only by finishing my earlier modification packages that I gained sufficient knowledge to tackle this mod package. I believe that my other mod packages were nice, but before now I can't really say that any of my mods couldn't be lived without. Apache Error Handler is the first mod I've written that I would put in the "can't live without" category.

@Charles, yes, of course. The Pretty Urls mod is incompatible with my Apache Error Handler mod, as are other web servers that don't run Apache. I think "totally" might be overstating the case however. I think a manual edit of the .htaccess file should allow my error handler to be called by Apache through the .htaccess and into SMF to land at the error script. It will require somebody to figure out what the Pretty Urls address of the error handler is, then an edit of the .htaccess to convert the error handler redirections to be compatible. If there is no compatible way to address the error handlers then we'll have to mod the mod and get PU to work with my mod. It doesn't sound too hard. My test SMF imploded when I installed PU and I made the decision that the URLs didn't make that much difference with search engines, so I gave up. Perhaps you or somebody with PU already working could figure it out and let me know if there's anything I should do to my mod to make the two work together. I hope it's just a matter of figuring out what PU needs to make a working path to the error handler.

Deprecated

Everybody should realize the power behind having Apache errors appear in your SMF log will in many cases open up a can of worms, revealing errors you wouldn't have even been aware of before. For example, most browsers ask for a favicon.ico file, the little graphic that appears in your browser's URL bar and bookmarks. You never realized before that all these 404 file not found transactions were going on because browsers are designed to not report them to site visitors, and you didn't have any error log before. There was no way you could have known they were there, although now all must realize that most SMF sites get hundreds, or depending on forum size thousands of 404 not founds from the missing favicon.ico alone.

So the first thing right off everybody will probably want to either install my Add Favicon.ico Support modification package to their SMF, or at least get the readme.txt file and go to one of the instant favicon.ico sites and throw together a favicon and put it in your root directory. The mod adds a few lines to SMF's HEAD section of your HTML to help some reluctant browsers find the favicon file, but that is unnecessary if you just want to get rid of the errors because any browser that asks for the favicon is going to know where to find it. Put the file there and you will eradicate the favicon 404 not found errors. Or install the mod and embrace the favicons. :) I rather like them and consider the favicons to be a nice little professional touch to finish off a nice SMF forum site.

All who are interested in Add Favicon.ico Support are asked to please direct any favicon questions to the mod's support thread. Please do not take the Add Apache Error Handler discussion thread off topic with favicon questions. Thank you. :)

Deprecated

#6
There is another thing I should mention right off, that perhaps there is one small misleading statement related to this mod package. Although the modification is designed to intercept the 500 Internal Server Error messages, Apache is not designed to send the 500 errors to custom error handlers. The 500 error in some cases is even caused by errors in your .htaccess file, so whan Apache decides that it cannot handle the .htaccess file it throws the file out the window and uses it's own error message instead of calling your error handler. But... My modification is compatible with accepting and reporting 500 error messages if Apache ever decides to send them to custom error handlers. :)

From the modification's readme.txt file:

QuotePlease understand that Error 500 Internal Server Error is internally generated by Apache when it is unable to handle a request for any reason. This occurs before your error handler can be called so it is unlikely that you will ever see an Error 500 display or log entries. It is not possible to intercept Error 500 under normal circumstances so this is not a failing of the modification.

That also brings up another interesting point. I suspect that the overwhelming majority of SMF forums run on Apache installed on top of Linux as the server's OS and Internet server. However, it is possible to install SMF on a Microsoft Windows server. While those servers do report 404 errors and the other standard HTTP error conditions, they do not as far as I know use .htaccess files, so this modification will not work in those situations. It is possible that there is some equivalent configuration file for Microsoft, but that is outside my knowledge. Bill Gates has so much money, so as far as I'm concerned he can fix it on his end! ;)

Check your hosting account or on SMF go to Admin -> Main -> Support and Credits -> and look at your Support Information report. It should have a line "Server Version: Apache ..." if you are running Apache on your server. If so you are good to go. If not, head back to SMF's mod shop and pick a different modification. :)

Charles Hill

I have weighed the usefulness of Pretty URLs mod vs this mod.  I have chosen this mod.  I had to add a little code to auto-redirect users from old "pretty" URLs to their un-pretty counterparts, but I like this mod :)

Deprecated

Thank you Charles! I'm very flattered. :)

I expect within a short time this mod will overtake all my other mods in total downloads and will become my most successful and useful modification package to date. The other mods were nice but this mod serves an important function. I think practically ever SMF forum should have this mod, the only exceptions being those where the admins don't really care about errors as long as the site plays okay.

One nice thing is that the code is not at all complex. ApacheError.php and ApacheError.template.php are straightforward and simple. The trickiest part was coding the helper script that modifies and unmodifies your .htaccess file. I made it as smart as I could so that it could do the best possible job in installing, and in particularly removing its changes to .htaccess files.

I'm expecting this mod to be pretty trouble free but I'll be here to handle any support requests. I'm pretty pleased with this one! :)

Charles Hill

Yea it very easy to make the changes I wanted.  I've already found and corrected several missing file errors :)

Deprecated

Exactly!!! One thing that experienced SMF administrators realize is that their error log is their best friend. It tells you if your forum is healthy or buggy. The only errors I can think of that you would expect to find in a healthy forum are the "Password incorrect" errors. People are idiots and often mistype their passwords. Ask me how I know. ;)

Charles Hill

Hey now... I type my password wrong sometimes too :)

mashby

Extremely cool mod. It's picking up 403s (I had to ban an IP address at the cpanel level as it was doing some strange stuff on my forum and continues to do so). Now I can see how often this IP tries to access my site. I now know it's many times today. Didn't know that before! Thank you for developing this one.
Always be a little kinder than necessary.
- James M. Barrie

Charles Hill

Only change I am considering making is making a separate error page or perhaps just an additional filter to filter out the extra errors... so that I can quickly find normal site errors.

kizer

I'd be interested in hearing how that filter works.

I don't mind knowing what my errors are, but if there are several man it can get over whelming trying to fix them all.

Maybe an ignore ***** would be nice.
Own a Jeep? Links4Jeeps.com

kizer

I know this is probably obivous, but if SMF is in a directory such as /forum its not going to change or report errors from say http://www.mainroot.com right? I'd hate to have to even try and deal with every possible missing file request because some ding dong is looking for dog.html and it doesn't exist or never did on the root of my domain.
Own a Jeep? Links4Jeeps.com

Deprecated

This modification installs or alters an .htaccess in the same directory as your forum's index.php, e.g. /forum. Apache will use that .htaccess file only for the /forum directory and subdirectories underneath it. Errors from above your /forum directory will be handled by whatever rules exist in higher level .htaccess files or by your hosting service's default error handlers.

karlbenson

#17
While this is a very nice mod.

Generally it is often better to redirect to a static html page which uses as little resources as possible.

Having these error build up in your smf error log could depending on the site, could cause some performance issues.
My warning would be to fix any issues immediately/asap as they arise.  Never ignore or just delete.

This is something I've been doing recently, on hack attempts, and such.  Keeping them from getting anywhere near from smf (saving queries and bandwidth) by sending them to a simple noindexed static html page http://www.youposted.com/error.html
As a result I have enjoyed increased performance.


Deprecated

Well, it has occurred to me that static error pages use less resources, and that having errors caused by a broken SMF being sent to the same broken SMF isn't entirely the best thing to do since it might be too broken to deliver an error page. And also while I haven't tested for this I imagine that if you put SMF into maintenance mode that your error pages will be offline too.

On the other hand my SMF forums run fine with very few errors, and almost all of them are "Password incorrect" errors. And I really like the integration of my error pages into SMF because it makes the whole site nice and consistent. I also like that the logging is all in one place and easily accessible. I really like the way this mod integrates the whole site seamlessly and I'm working on other mods that integrate even more functions into SMF's look and feel. In the end I want every page on the domain to be something served by SMF with no external packages required.

It's a matter of personal preference, and no one viewpoint is any more valid than the other.

Sabre™

Nice job mate. :)
Could you add an area, where under your maintenance section in the AP, you would have 404 separate?
eg.
before:
Forum Maintenance
Generate Reports
Forum Error Log
Moderation Log


after:

Forum Maintenance
Generate Reports

404 error log
Forum Error Log
Moderation Log


Or would this be too heavy?

regards
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


Advertisement: