PDA

View Full Version : Custom HTTP Error Documents


JJR512
07-28-2002, 10:00 PM
I've made a little hack that will show custom HTTP error documents to any visitor to your site, if he or she creates the error condition. These are errors like 404 (file not found) or 500 (internal server error). I've included processing for about 23 various HTTP errors.

The error documents are templates within vBulletin, but these do not apply only to vBulletin. Any visitor to any part of your site would see the error document (if appropriate). Now obviously this means that this hack should not be used by those of you that do not allow guest/unlogged-in viewing of your board, because if a guest creates an error condition, he/she would only see the vBulletin "not logged in or no permission" message, which wouldn't be very useful.

This hack also involves modifying your .htaccess file, and I believe only Apache-powered servers use that (correct me if I'm wrong). Because screwing up that file can make your site unusable, make sure you keep a backup copy of it, and if you can't find a .htaccess file in your root web directory, check with your webhost to see if they've hidden it, which is often the case. DO NOT just make a new, blank .htaccess file and upload it because you may overwrite a hidden one, potentially killing your site.

As you can probably tell by now, this hack is perhaps not an appropriate choice for the complete newbie. I strongly suggest that you use this hack only if you read the directions and actually understand them; many times, people just blindly follow the instructions without a clue as to what they're doing, and usually, this is fine, but I'm warning you now, you can hurt your site if you screw this up, and if you don't know what you're doing, you won't know how to fix it if/when you do screw it up.

(By now you may be asking why I'm releasing this. Well, I did it originally for my own site, and figured some others of you may like it as well. This is actually a very simple hack to install; it involves only one file mod, one new very small file, and importing one file into the db, and that's it. You may wish to modify/customize the templates as you desire. You will find them in with the regular vB templates in the section "HTTP Error Templates".)

For a demo, please visit this non-existant page on my website, to show you a 404 (other errors look similar, with customized messages): http://www.jjr512.com/ddkd4iafgi8d.php

Chris M
07-29-2002, 09:28 AM
Cool!

*Installs*

Satan

Admin
07-29-2002, 10:00 AM
Any particular reason for this? ;)
$error = $error;

Good hack. :)

DemiNeo0101
07-29-2002, 12:19 PM
I got a problem. Everytime i try to get the error page it pops up http://www.yourdomain.com/forums/error.php and not my site. hehe j/k :). Very very nice hack.

* DemiNeo0101 clicks install

DrkFusion
07-29-2002, 01:28 PM
I think your supposed to change a little variable so it says your domain instead of yourdomain.com

Drk

LouChipher
07-29-2002, 01:32 PM
would somebody release a german version? ;) :)

afterlab
07-29-2002, 01:37 PM
Nice hack, i'll try and install it.

DrkFusion
07-29-2002, 01:52 PM
Try? Come on, you can do better then try..

Nice hack man, works fine on my board...thanks again great hack

Drk

Floris
07-29-2002, 02:58 PM
I am using cpanel 4.9 which lets me make my own 404 error pages etc, can this be used easily with that?

afterlab
07-29-2002, 03:19 PM
heh, well I tried and it worked.. So boom bang bang brotha -- Nice hack! :rambo:

Floris
07-29-2002, 03:21 PM
Tried it, ..

cpanel 4.9 lets you save as 400.shtml etc.
So I just put in a meta refresh tag for 0s to redirect to the error.php and it works now very nice :)

Dean C
07-29-2002, 03:28 PM
1. Import the newtemplates.sql into your database. NOTE: You should make a backup of your database first, or at least of the template table.


How do i do this :)?

Ian
07-29-2002, 03:46 PM
Originally posted by Mist
How do i do this :)?I'm wondering the same thing.

Floris
07-29-2002, 03:48 PM
Run an SQL query :)

phpMyAdmin = your best friend.

Ian
07-29-2002, 03:54 PM
Originally posted by xiphoid
Run an SQL query :)

phpMyAdmin = your best friend.Could you elaborate on this? I have phpMyAdmin installed and I've used it many times... How do I import the file?

Floris
07-29-2002, 04:00 PM
I'd say .. read the manual.

But.. you could copy paste the content of the .sql file to the big input window and press go. it will run the query then.

Takara
07-29-2002, 04:20 PM
Just a note, in the instructions it says

In the .htaccess file, locate any lines beginning with "ErrorDocument". Erase those and replace with the following code. If you do not have any lines like that, just add this at the end of the file.

ErrorDocument 400 http://www.yourdomain.com/forums/error.php?error=400
ErrorDocument 401 http://www.yourdomain.com/forums/error.php?error=401
ErrorDocument 403 http://www.yourdomain.com/forums/error.php?error=403
ErrorDocument 404 http://www.yourdomain.com/forums/error.php?error=404
ErrorDocument 405 http://www.yourdomain.com/forums/error.php?error=405
ErrorDocument 406 http://www.yourdomain.com/forums/error.php?error=406
ErrorDocument 407 http://www.yourdomain.com/forums/error.php?error=407

If you just add the path, and leave out your domain the error document will take the place of the URL.. soo.. by going to dasdsa.php it leaves the url as dasdsa.php and gives the error reason. Otherwise it redirects you to the error.php ^^

JJR512
07-29-2002, 06:53 PM
Originally posted by FireFly
Any particular reason for this? ;)
$error = $error;

Good hack. :)
:o Nope! :D

Well, actually, when I first tested it, I wasn't getting the number to show up in the browser title bar. So I figured maybe for the variable to get parsed into the template it had to be explicitly declared, which is why I did that. But I think I just needed to refresh or something...anyway, it started working, I don't know why, but it did, and I forgot to take that part out. :)

LouChipher: I can't release a German version myself, since I don't speak it well enough to translate it. But it should be easy, since all the language is in the templates. If anyone else wants to do it, by all means, feel free.

Ian: If you can use phpMyAdmin, it's easy. You can do what xiphoid said, which is to open the file newtemplates.sql, copy the entire contents, go to phpMyAdmin, on the screen where you see the list of tables in the left pane and below that you have a text box labelled "Run SQL query/queries...", paste the contents of the file into that box, and hit the Go button. Or, an easier way is to go to that same spot in phpMyAdmin, but below that text box is a smaller field with a Browse...button, which you can use to point it to the file newtemplates.sql, then hit the Go button. That will upload the file into the server's memory and execute the instructions inside it.

Takara: I'm not quite sure I understand what you're saying. Are you saying in the .htaccess file, on the ErrorDocument xxx lines, I can make the path to error.php be relative, not full? Just make it like ErrorDocument 400 forums/error.php?error=400?

Velocd
07-29-2002, 10:41 PM
Very nice hack, looks great. I also use the cpanel for custom error documents, so I'll have to look into xiphoid tip on integrating it ;)

JJR512
07-29-2002, 10:48 PM
I believe the various cpanels that let you add custom error documents only help to automate the process. That does not (or shouldn't) exclude the ability to do it manually. If you create a custom 404 page, for example, it just saves that page for you somewhere and adds the appropriate line to .htaccess. If you can edit .htaccess manually, you can do this hack. :)

Neo
07-30-2002, 12:03 AM
Marry me JJR512 ;)

FWC
07-30-2002, 05:50 AM
Originally posted by JJR512
Takara: I'm not quite sure I understand what you're saying. Are you saying in the .htaccess file, on the ErrorDocument xxx lines, I can make the path to error.php be relative, not full? Just make it like ErrorDocument 400 forums/error.php?error=400? Actually, the paths should be relative. You are not supposed to use full url's in error document redirections in .htaccess. It will fill the Apache error log up with error messages. They should look like:

ErrorDocument 400 /forums/error.php?error=400

JJR512
07-30-2002, 05:58 AM
Tested, yep, it works like that. :)

LouChipher
07-30-2002, 09:10 AM
Originally posted by JJR512
LouChipher: I can't release a German version myself, since I don't speak it well enough to translate it. But it should be easy, since all the language is in the templates. If anyone else wants to do it, by all means, feel free.


I know, but somebody should do this... ;)

Chris M
07-30-2002, 09:39 AM
Originally posted by Neo
Marry me JJR512 ;)

The movie : "Indecent Proposal" comes to mind;):p

Satan

DemiNeo0101
07-30-2002, 03:09 PM
ok here is an interesting bad bug i foun thats gona keep me from useing this great hack. in the online users for 90% of my users it shows: Unknown Location: /forums/error.php?error=404 (in included a screen shot) even for me even know im viewing online.php. It does this same thing on you forums to JJR512 except it seems you modifyed your online.php to make it look cleaner.

might wanna get this fixed b/c i use my online.php alot.

Floris
07-30-2002, 04:18 PM
This is NOT a bug.

Every different file that is not set in the source code of vBulletin, will display as unknown location. You have to edit it.

JJR512
07-30-2002, 07:29 PM
To make it look nicer in Who's Online:

Open online.php

Find:
case 'gallery':
$userinfo[where] = "Viewing Picture <a href='gallery.php?s=$session[sessionhash]'>Gallery</a>";
break;
Under that, add:
// HTTP Errors
case 'httperror':
$userinfo[where] = "Experiencing an HTTP Error";
break;
// End HTTP Errors
Find:
case 'gallery.php':
$userinfo[activity] = 'gallery';
break;
Under that, add:
// HTTP Errors
case 'error.php':
$userinfo[activity] = "httperror";
break;
// End HTTP Errors
That's it. :)

DemiNeo0101
07-30-2002, 08:43 PM
why do all thoughs errors go away when i take the error.php out then? And for me it shows the error and im looking at the online.php

JJR512
07-31-2002, 01:24 AM
I'm sorry...I'm not quite certain I understand the problem here. :confused:

DemiNeo0101
07-31-2002, 01:37 PM
when i delete the error.php file from my server, all the errors (unknown location errors) go away, and just show were everyone really is.

DemiNeo0101
07-31-2002, 01:40 PM
when i delete the error.php file from my server, all the errors (unknown location errors) go away, and just show were everyone really is. it does that on EVERY vbb that this hack is on it seems. Even yours. And like i said over 90% of the users on the users online.php have that error as there location.

JJR512
07-31-2002, 02:10 PM
Are you saying you have a bunch of people online that are being shown as having an HTTP error, but they're really not having an error, they're somewhere else doing something else?

DrkFusion
07-31-2002, 04:51 PM
Nice, i love this hack :)
Works great!
Drk

DemiNeo0101
08-01-2002, 04:18 PM
yes exactaly.

http://www.undergroundcandy.net/forums/online.php

look for yourself

DrkFusion
08-01-2002, 05:09 PM
Hey, maybe you can provide us some sort of guest login

Drk

DemiNeo0101
08-01-2002, 08:12 PM
i took the error.php out. Admins were having a fit that the online.php was not there. ill just make my own files.

JJR512
08-01-2002, 08:17 PM
I still don't know what you mean. Do you understand that we can't see what it is you're talking about in Post #35, because, as DrkFusion said, guests can't see your board? I also don't understand why online.php wasn't there because error.php was.

JJR512
08-16-2002, 12:51 AM
I just received an email notification about a reply to that thread. The reply appears to have been deleted, or for some other reason, I can't see it. But, because the notification email contained the message, I can still address it.

For the record, the reply was a question:
I must say this is a excellent hack I just have one problem. I recently created another style and was wondering how I would go about importing the templates in the .sql into the new templateset. How do I add the templates in the .sql file into the database?
The answer is that the templates are installed as default templates. This means it's like they're an original part of vBulletin. They show up where the other templates that come with vB show up, not at the top of the list where custom templates show up. This means they will be active in every templateset you have. The only downside is that when you upgrade vBulletin, you will need to reinstall the templates, by once again importing the .sql file.

Amasov
08-14-2003, 08:53 AM
Nice hack :) I've installed it, but looking in the apache-docs (2.0.xx) i found:

In addition, if you use a remote URL in an ErrorDocument 401, the client will not know to prompt the user for a password since it will not receive the 401 status code. Therefore, if you use an ErrorDocument 401 directive then it must refer to a local document.

fixed :p

Dodger
08-20-2003, 06:35 AM
I have an error running query:
Duplicate entry '757' for key 1
Help me plz.

NuclioN
08-20-2003, 11:57 AM
The same here.. duplicate key errors. Maybe someone can post the templates.

--edit-- never mind i've changed the keys by adding a 7 in front. That range is not present at this moment. Good hack.

drumsy
08-20-2003, 05:58 PM
I installed this and my site could no longer be accessed! :(

GuruXL
04-19-2004, 06:08 AM
Would anybody be interested in helping me make a similar hack for vB 3.0?