Drupal allows the site admin to assign a node to the 404 (page not found) and 403 (access denied) errors. However, if you assign a regular node to them, these nodes appear under a taxonomy term, are visible in searches, and may appear in node lists.

Therefore, I created a new module, customerror, which allows the site admin to create custom 404 and 403 errors without the need to have them as standalone nodes.

You can add any HTML formatted text in the page, in which you can have a link to your FAQ, your site map, contact information, ...etc.

Since the module is targeted to novice site admins, it does not require any database changes.

Comments

moebis’s picture

Tried it with 4.6 CVS and it loads up, but when you point to a non-exiting page you still get the standard Drupal "Page not Found" page. Is this because 4.6 handles it differently?

Dublin Drupaller’s picture

Hey KB..

Great module. Very simple to install and very useful for thickos like me. nice one.

I just tried it with 4.6 and I forgot to change the ADMINISTER -->> SETTINGS -- default 404 page & default 403 page pointers so I got the same as you Moebis.

Make sure you go to ADMINISTER -->> SETTINGS

and point your DEFAULT 404 PAGE & DEFAULT 403 PAGE to the customerror/404 and customerror/403 links respectively.

Works great.

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

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

moebis’s picture

Hey Dublin, thanks for the tip, I didn't even bother to install the customerror module this time round, I simply created a page without assigning taxonomy, and unchecked "Publish". Then I looked in Settings like you said, gave it "node/24" at the pointer for a custom error page, and voila it works, and guess what? It's not included in the searches (I ran the cron job twice to double check). So this maybe a useless module. Am I missing something?

The key is to NOT PUBLISH, try it.

kbahey’s picture

If it is unpublished, then how are anonymous users supposed to see it?

Were you logged in as user 1 when you checked the 404? Try logging off and see what happens.

Also, some sites have the taxonomy as mandatory, so not assigning a taxonomy is not an option for them.
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

moebis’s picture

I was logged off, cookies cleared everything. Check my site.... here is a bogus link that will pull the error, using default Drupal settings: www.moebis.com/test or www.moebis.com/anythingyouwant

There is "always" the capability of not assigning taxonomy to a piece of content. Sorry, but it really does work with a standard Drupal 4.6 install, without the customerror module.

Do a search on my site for 404 or 403 or page not found. Nothing comes up, like it's supposed to, because it's NOT PUBLISHED.

Dublin Drupaller’s picture

Hey..!

the same worked for me...did exactly what you outlined and it worked with drupal 4.6..for both logged in users and not logged in users.

I remember trying that on previous versions of drupal and it wouldn't work for me....but..by NOT PUBLISHing the page it works fine.

I also assume by NOT PUBLISHing it means it won't show up in the search but the drupal system can still find it.

Thanks for thr heads up.

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

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

moebis’s picture

So you're saying it DID WORK without the customerror module in 4.6.0 RC?

www.moebis.com

Dublin Drupaller’s picture

Yep...i didn't need the customerror module in drupal 4.6...the instructions you mentioned worked perfectly

I remember trying to do just that in previous versions of drupal and it wouldn't work..so I didn't bother trying until you mentioned it.

Thanks again for the heads up...

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

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

kbahey’s picture

Dub

What if the taxonomy is mandatory?
In this case all nodes of a certain type must have a taxonomy associated with it. Right?
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

kbahey’s picture

Great module. Very simple to install and very useful for thickos like me. nice one.

Yes, simplicity was design requirement number one. No database tables, no permissions. After all, there is no point in putting permissions for something that is supposed to be visible for everyone.
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

gdip’s picture

One tiny remark though.
I think that a clarifying explanation similar to Dublin Drupaller's should make its way into this modules INSTALL.txt.

kbahey’s picture

Thanks gdip

Which comment by Dub are you referring to?

Please copy/paste in a reply to this comment, and I will include it in the INSTALL.txt

--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

gdip’s picture

Hi kbahey!

I rewrote parts of the installation text and also added an item (hope you don't mind).
Since there are quite a few non native English-speaking Drupal admins, I tried to be a little bit more verbose (maybe too much?).
If you intend to use it (no need for any kind of credit), please check for typos and other errors.
Cheers
---
This module requires drupal 4.5.x or greater.

Installation:
-------------

Text should be entered without quotation marks!

1. - Copy the customerror.module to the Drupal modules/ directory.

2. - Goto administer->modules
- Enable the customerror module

3. Configure the module
- Goto administer->settings->customerror
- Enter any title and description you want for 404 and 403 errors.
HTML tags are allowed to format the text.

4. Enable your customerror pages.
- Goto administer->settings.
- Scroll down to "Error handling".
- In the field below "Default 403 (access denied) page:"
enter "customerror/403".
- In the field below "Default 404 (not found) page:"
enter "customerror/404".
- Scroll down and click "Save configuration".

5. Test your error pages.
- Copy your present admin page url.
- Try to go to a non-existent Drupal page on your site.
You should see your custom error page for 404 (not found) page .
- Log out from your site.
- Paste the admin page url and try to go there.
You should see your custom error page for 403 (access denied) page.

kbahey’s picture

I updated the INSTALL.txt to include your instructions.

Thanks for the detailed steps.
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

kbahey’s picture

Well it works fine for me.

Are you sure you followed the instructions in the INSTALL.txt correctly?

You have to set the 404 in admin/settings to customerror/404 and the 403 to customerror/403
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

moebis’s picture

I just checked my site, and I can see you tested it, so what do you think? BTW a tracert showed you're in Chicago somewhere. ;-)

www.moebis.com

kbahey’s picture

That was not me. And no i am not in Chicago.

No need to make a big deal out of nothing.
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

moebis’s picture

I just want to be clear that I am in no way knocking you. I see there is a need for this module in earlier versions of Drupal, also considering most are using 4.5.2 now. I just wanted to make sure you understand that they seem to have fixed the "Not Published" tag, which will help with many things in the future.

We need developers like you in our community, and I for one am very grateful for your time you guys spend on these projects. Keep up the hard work!

BTW, I guess I was wrong about my tracert, I feel stupid now. ;-)

Regards, Moebis

www.moebis.com

kbahey’s picture

I am adding a note on the project page that this may not be needed for 4.6.

But before I do that, I want confirmation on two things. If moebis and dub can help there, I would appreciate it:

1. Unpublished nodes are viewable in 4.6. Is this a by-design thing? My live sites are still 4.5 and when I unpublish a node, I don't want anyone to view it. So this can be just a bug or an unintentional side effect.

2. What if taxonomy is required? Does the 404 and 403 as nodes get listed?

If 4.6 behavior that you guys discovered is by design and assured to remain so, and taxonomy is not mandatory, I will update the project page to mention those finding.
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

Dublin Drupaller’s picture

Quick answers..

(1) re: UNPUBLISHED NODES VIEWABLE in 4.6.

Not on my drupal 4.6 installation. When I NOT PUBLISH a node, it doesn't appear, unless I call it directly by typing in the link to the URL address bar.

So, I assume it is by-design and does exactly what it says on the tin. i.e. PUBLISHED nodes appears whereas NOT PUBLISHED nodes don't. I also guess the drupal system can call it up itself and bypass the content settings for the custom 404 & custom 403 pages....

Just tried moebis's tip for custom error page with 4.5.2 and his idea works on that as well.

(2) re: what if taxonomy required? does the 404 and 403 as nodes get listed?

No idea and not sure what you mean. Sorry. get listed where?

The out-of-the-box settings for drupal 4.6. allows moebis' solution to work without any tweaking. Assume if a drupal site administrator is getting into sophisticated taxonomy control they understand what they are doing and will act accordingly if it makes any difference.

Hope that helps

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

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

kbahey’s picture

On my sites, taxonomies are mandatory. This means that any node must belong to some hierarchy.

This means that browsing to taxonomy/term/xx will show a node list of nodes belonging to this term.

If taxonomies are not mandatory, then moebius approach will work, but when it is mandatory, this solution is not an option, and this is why I wrote customerror. To avoid having 404 and 403 nodes listed under miscellaneous in modules like site menu and others.

Clearer now?
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

kbahey’s picture

After downloading todays tar ball of 4.6 RC and doing some tests here are the results:

1. An unpublished node is not viewable to any one but those who have
"administer nodes" permission. This means that anonymous visitors and
registered users do not see unpublished nodes. Not sure how dub got to see an unpublished node by directly typing the URL.

2. If the default 404 and default 403 settings in /admin/settings are
set to an unpublished node that node is still visible indirectly (i.e.
when a visitor goes to a URL that causes a 404 or 403).
--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

moebis’s picture

Kbahey,

I just tried your test. It's even better then I thought. If a node is not published it does not show up to anyone but admin, EXCEPT if it is listed on the settings 403 and 404 page. Cool, so, someone, somewhere figured this out well. You retain the functionality of an unpublished node (hidden even if someone tries to go to the direct node they get a 403 error), but if the unpublished node is listed as a 403 or 404 page then it does pull up either 1) Directly or 2) when a 403 or 404 is called AND 3) WILL NOT SHOW UP IN A SEARCH. Nice eh?

www.moebis.com

Dublin Drupaller’s picture

Sorry KB..you're right...

just to clarify...I tried the following...(with drupal 4.6)

WITHOUT CUSTOM ERROR MODULE INSTALLED (using NOT PUBLISHED NODES)

1. anonymous user
2. access content switched off for anonymous users
3. default 404 is pointing to a test unpublished node/4
4. default 403 is pointing to an unpublished node/3

Results:

A) anonymous user gets a BLANK PAGE..when trying to access a non-existing page (404)

B) anonymous user gets the drupal "not authorized" message (not the custom node/3 page) when trying to access an existing page.

WITHOUT CUSTOM ERROR MODULE INSTALLED (using NOT PUBLISHED NODES)

1. anonymous user
2. access content switched ON for anonymous users
3. default 404 is pointing to a test unpublished node/4
4. default 403 is pointing to an unpublished node/3

Results:

A) anonymous user gets the custom 404 (node/4)..when trying to access a non-existing page

B) anonymous user gets the custom 403 (node/3) when trying to access an existing page they are not allowed to view.

WITHOUT CUSTOM ERROR MODULE INSTALLED (using PUBLISHED nodes)

1. anonymous user
2. access content switched OFF for anonymous users
3. default 404 is pointing to a test published node/4
4. default 403 is pointing to a test published node/3

Results:

A) anonymous user gets a BLANK PAGE..when trying to access a non-existing page (404)

B) anonymous user gets the drupal "not authorized" message (not the custom node/3 page) when trying to access an existing page.

WITHOUT CUSTOM ERROR MODULE INSTALLED (using PUBLISHED nodes)

1. anonymous user
2. access content switched ON for anonymous users
3. default 404 is pointing to a test published node/4
4. default 403 is pointing to a test published node/3

Results:

A) anonymous user gets the custom 404 (node/4)..when trying to access a non-existing page

B) anonymous user gets the custom 403 (node/3) when trying to access an existing page they are not allowed to view.

WITH CUSTOM ERROR MODULE INSTALLED

1. anonymous user
2. access content switched OFF for anonymous users
3. default 404 is pointing to customerror/4
4. default 403 is pointing to customerror/3

Results:

A) anonymous user gets the custom 404 (customerror/4)..when trying to access a non-existing page

B) anonymous user gets the custom 403 (customerror/3) when trying to access an existing page they are not allowed to view.

Hope that (extensive test) helps clears it up..

apologies KB..didn't take my time when testing it for your earlier. As you can see, there is a value of the customerror.module.

After taking the extra time to test what you asked...I will definitely be using it and will follow up with that offer of a PHP patch that will allow users to insert PHP code into the custopm 404/403 pages.

Cheers

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

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