Welcome Guest | Login

How to trap 404's?

Hey everyone!  I'm still a bit wet behind the ears - so forgive me if this is super easy...so here goes:

Within my rails application, I have the plugin ExceptionNotifier installed.  However, every "Page Not Found" or Path not found error generates an email.  Needless to say, I am getting a ton of emails from "hackers" trying to whack my site with obscure requests.  Also, I would like people to get a page not found template/page vs. the generic server error page.  

Any insight to how I can achieve this?  Thanks in advance!

-H

2007-08-29 01:25 PM

You know what you know...and don't know what you don't know
Horatio - You can add the custom error pages to your app's .htaccess file. If you have a look into your current .htaccess file you can see the custom page set for 500 error and you can add the same for 404 error also which is the error code for "Page Not found". You may need to create a 404.html file to display the custom message.

2007-08-29 03:20 PM

Sijin,
I believe that I will still generate an exception (from rails) for a bad url.  I was wondering if there was something within the framework that would trap that "no route found to match" rails error.  Again, I might be missing something obvious here.

Thanks for your reply -
-H

2007-08-29 03:40 PM

You know what you know...and don't know what you don't know
Just put something like this at the bottom of your routes.rb file

map.notfound '*args', :controller => 'some_controller', :action => 'the404'

2007-08-29 04:51 PM

Also are you using an up-to-date version of ExceptionNotifier?  

Furthermore, I've also see  map.connect '*anything' and  map.connect '*path' used.

2007-08-29 04:56 PM

William -

That worked like a charm!!  Thanks so much!  This will cut down the excess email I've been getting from my ExceptionNotifier.

map.notfound '*args', :controller => 'some_controller', :action => 'the404'

-H

2007-08-29 06:01 PM

You know what you know...and don't know what you don't know
Thanks to all of the help... I knew where to look for more info:  In the API documentation on routes.rb

Route globbing

Specifying *[string] as part of a rule like :

map.connect '*path' , :controller => 'blog' , :action => 'unrecognized?'

will glob all remaining parts of the route that were not recognized earlier. This idiom must appear at the end of the path. The globbed values are in params[:path] in this case.

2007-08-30 08:17 AM

You know what you know...and don't know what you don't know

Hello Guest! In order to post you must be an active client with us, please log in or sign up today!