Hello,

I have drupal up and running, however when someone goes to a page that does not exist they get taken to the index page. Where do I set the custom 404 error page? Am I missing something simple?

Best regards,
Brett

Comments

Dublin Drupaller’s picture

Am using the latest version of drupal, not sure if you are using the same, but, all I have to do to set the custom 404 page is do the following:

a) log into the site as an administrator

b) create a new page that is going to be your new 404 error page..make a note of the link

c) click through to the configuration page

d) scroll down and there are options for re-directing for 404 errors and which page to go to.

e) insert the link to your new error page here.

f) save your configurations

As an addendum I was getting a lot of "can't send header" errors when I was setting up my first drupal site - which isn't a 404..i think it's a 500 error..or something like that....

It was a major pain in the arse...So I ended up setting up a special script that was like a "catch all" faciility that not only redirected the user to a custom error page, but emailed me as well with a reference to the error, time of day, etc.

Please also note that I'm not an experienced programmer...even I was able to setup that "Catch all errors and email me" script.

Came in very handy the other night when the site couldn't connect to the SQL...I would have been blissfully unaware, if I hadn't have got the automatic email from the script.

Let me know if you want a copy and instructions...will be working late tonight(Thursday - it's 20:00 in Dublin) so will be hovering here for a while.

Cheers

Jason

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

cornernote’s picture

Hello,

I am using version 4.3.x so I think that is why I cannot see it in my config. I just checked the new version and it is there. Just having some teething issues upgrading.

The reason I wanted to make the 404 was so that I could make it email me the error message and the refering page. Sounds like you have a few nice features in yours. I would love a copy.

Thanks.

Best regards,
Brett

Dublin Drupaller’s picture

not too sure how to post up something like that...theres a few files..can put together simple instructions...

will drop back later when I get a chance.

Jason

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

cornernote’s picture

Hello,

Just type the file name using the bold tags, then past the file body using the code tags. You may have to replace the < and > tags with &lt; and &gt; so they dont get lost.

Dublin Drupaller’s picture

Okay...

(mini disclaimer - I'm very new to this site and drupal. Only installed it on my own server last week and am not a programmer, so please be careful. I have tried to keep it a simple as possible.)

Here's the "catch-all and email me" error CGI script that I mentioned in previous posts. All it does is redirects the user to a special error page and sends an email alert.

The only thing it does above and beyond the redirect 404 option in Drupals configuration sreen (version 4.4) is that it automatically emails you a red flag when an error occurs.

Here's an example email:


A 500(Internal Server Error) error occurred on
thesite.com/drupal/index.php at Fri May 7 00:35:12 2004, and a 459-byte response was sent to the client (the.users.ip.address). The referring page was thesite.com/drupal/?q=user/view/14.

There are three files that require editing and uploading to specific folders. Main editing to be done is just the path and a few minor adjustments to the CGI file. Instructions are given in the CGI file, so it should be easy to follow.

FILE 1
---------
.htaccess - goes in the root directory of your server or appended to an existing .htaccess file

ErrorDocument 404 /drupal/http-error.cgi
ErrorDocument 500 /drupal/http-error.cgi

You need to edit this file to match the path to where the http-error.cgi (e.g. /drupal/http-error.cgi) and which errors are picked up..i.e. 500 system errors or/and 404 file not found errors.

FILE 2
----------
http-error.cgi - goes in your /drupal/ folder

open it up at the following link: (sorry...I don't know how to put it into a post here. I tried, but it gave me an error message.."suspicious content"... or something like that)

http://www.m3m.eu.com/drupal-script/http-error.txt

Here you specify the email address that error alerts are sent to, the path to the http-error.html file i.e. what the user sees when an error occurs and what type of errors you want caught...

FILE 3
----------
http-error.html - This is what is referenced when there is a 500 or/and 404 error. It goes in your /cgi-data/drupal/ folder and is completely customizable. (I'm assuming that it could go into /anyfolder/ outside your PUBLIC_HTML folder. Just as long as the http-error.cgi file knows where to find it).

Open it up at the following link (go to VIEW SOURCE for the code)

http://www.m3m.eu.com/drupal-script/http-error.html

2. Notes:

a) Obviously all the files should be uploaded into their respective folders in ASCII format to the server. CHMOD 755 for the CGI script when it's up there.

b) I'm on an apache/red hat type server and it works a treat. I am a NEWBIE to all this stuff, so, I haven't got a clue what to do on other types of servers.

c) there are remarks/instructions in the CGI file that makes it fairly simple to modify - even I could do it and get it working!

d) You may have to edit the path to Perl in the first line of the CGI script.

e) the CGI script uses SENDMAIL to send the email. no idea what to do if you don't have that on your server. sorry.

f) as a newbie the only warning I can think of mentioning is that when you're uploading the .htaccess file to the root directory of your server, make sure there isn't one there already and you overwrite it. Back up the contents of your root folder before trying it.

Hope it works for ya!

I know there is a 404 redirect option on Drupals configuration page for 4.4, but, the added function of getting an email warning each time a 404 or 500 system error occurs saved my ass earlier this week.

My SQL stopped working for some reason on my server and I would have been oblivious to this fact if I hadn't have had the "catch-all" http-error.cgi installed - until I tried to pop into the site myself, of course.

So I found it was worth the effort just for the added email alert feature. I was able to get on the phone straight away to technical support at the hosting company I'm with and they were able to sort the issue straight away for me.

Jason

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

cornernote’s picture

Hello,

I will convert it to a PHP script shortly so that it does not require sendmail. Thanks for the code!

Best regards,
Brett

cybe’s picture

Is there anyone here who could provide me with code to make a 404 page automatically include a search to what he was trying to access:

if someone goes to http://site/jamesbomb

and it doesn't exist (jamesbond does)

the 404-page will automatically show search for jamesbomb on the page..

I have a piece of code from a site that does things like this, but I can't modify if very well because of my lack of skills.. What this nice piece of script does is, it does a SOUNDEX thingy, which makes jamesbomb and jamesbond the same because they almost are the same.

Would it be possible to use soundex in drupals search, so that for instance, after the normal search results are some:

"perhaps you meant: jamesbond" results? well, just like google does basically.. (btw microsoft just patented double clicking)

urbanfalcon’s picture

What you're looking for has already been made, go here to find it: http://www.settingtheworldtorights.com/node/417

rickvug’s picture

Search404 Module

This module is based on a lot of the code floating around this thread and others. Please contribute feature request and patches to it so that we can all use a "best of the bread" solution. Thanks.

Here are some related form discussions and other related links that I have found that may help:
http://drupal.org/node/12668
http://drupal.org/node/7570
https://svn.bryght.com/dev/wiki/CustomPageNotFoundSearchPage
http://www.settingtheworldtorights.com/node/417
-------------------------------------------------------------------
Rick Vugteveen | Image X Media (work) | Blog (personal)

-------------------------------------------------------------------
Rick Vugteveen |rickvug.com @rickvug on Twitter