Jump to content

Custom error pages


son

Recommended Posts

I have created the usual error files for a new site and uploaded them into the folder 'more'. In .htaccess I have the following:ErrorDocument 401 /more/401.phpErrorDocument 403 /more/403.phpErrorDocument 404 /more/404.phpErrorDocument 500 /more/500.phpTyping in a wrong file name it just displays the generic error message, not mine. Could it be that the hosting company disabled custom error documents? I used .htacess like this often before without any problems...Son

Link to comment
Share on other sites

Could be. Try asking them.
I was on the phone for hours today and in end they said they get back to me when they found why it is not working. In the end they amended my .htacess. Apparently, they support 401, 403, 500 as .php, but not 404 (I wish they would have said that when I told them I use .php - could have saved me lots of telepone costs;-)). The file is now as:
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule (.*) /404.php

I checked on apache.org, but do not completely understand what it does. It puts the rewrite engine on, the says that the rewrite condition does not apply for files or directories? (is this right?), but it applies to the 404.php, so it can have a .php ending? Is this right?Son

Link to comment
Share on other sites

It first check if the requested filename exists, then if a directory with this name exists, and if neither, it rewrites all of the characters in the URL to the URL "/404.php" (i.e. your 404 page).I must say, it seems there is some sort of a bug with the host's OS. They simply never found it. During the time between your calls, they were trying to fix it, but obviously they failed. This URL rewriting is only a workaround for that bug. Still, it gets the job done, so... be happy :) .

Link to comment
Share on other sites

It first check if the requested filename exists, then if a directory with this name exists, and if neither, it rewrites all of the characters in the URL to the URL "/404.php" (i.e. your 404 page).I must say, it seems there is some sort of a bug with the host's OS. They simply never found it. During the time between your calls, they were trying to fix it, but obviously they failed. This URL rewriting is only a workaround for that bug. Still, it gets the job done, so... be happy :) .
Thanks for your input. Is it then quite uncommon that a hosting company does not allow 404.php files? I never had problems in past using php files for that purpose. Also, do you think as this is just a workaround there might still be an issue with 401, 403 and 500? After hours of investigation they claim it is only the 404, which cannot be a php file, but I would like to double check...Son
Link to comment
Share on other sites

Thanks for your input. Is it then quite uncommon that a hosting company does not allow 404.php files? I never had problems in past using php files for that purpose. Also, do you think as this is just a workaround there might still be an issue with 401, 403 and 500? After hours of investigation they claim it is only the 404, which cannot be a php file, but I would like to double check...Son
Feel free to check for yourself.Yes, it's uncommon for that to happen. You're either allowed to execute PHP in all of your space, or are not allowed to execute PHP at all. And you're either able to use .htaccess for all error code pages, or you're not able to set up any error pages.If it's just 404, it may be a bug in Apache, or PHP, or their OS of choise, or just the combination of all of those they use may prove to be the cause for this. They were trying to see which one of those was the cause, and upgrade/downgrade that.If they are sure it's only with 404 pages, it could mean they have discovered what is causing the problem, but can't upgrade just yet for whatever reason (eg. if it's the OS, there may simply not be a newer version to fix the bug just yet).
Link to comment
Share on other sites

Feel free to check for yourself.Yes, it's uncommon for that to happen. You're either allowed to execute PHP in all of your space, or are not allowed to execute PHP at all. And you're either able to use .htaccess for all error code pages, or you're not able to set up any error pages.If it's just 404, it may be a bug in Apache, or PHP, or their OS of choise, or just the combination of all of those they use may prove to be the cause for this. They were trying to see which one of those was the cause, and upgrade/downgrade that.If they are sure it's only with 404 pages, it could mean they have discovered what is causing the problem, but can't upgrade just yet for whatever reason (eg. if it's the OS, there may simply not be a newer version to fix the bug just yet).
I just password protected a folder with an .htaccess file without putting any other files as .htaccess and .htpassword in it. Entering the right credentials it shows our customised 403 page correctly. Entering the wrong credentials three times it shows the generic 401, not ours (which is not great). So, there is at least one more problem with 401. Is there a way to test 500? Not sure if you can do that... Also, not sure if that is important, but when I set up website on host I had problems with dynamic pages. I had following entry in .htaccess 'SetEnv DEFAULT_PHP_VERSION 5', which did not work and hosting company changed it to 'AddHandler x-mapp-php5 .php'. Not sure if that is relevant, but thought it might be worth mentioning...Son
Link to comment
Share on other sites

You can test 500 by creating .htaccess that sets it up in one folder, and place another .htaccess in a subfolder. The inner .htaccess file can cause the error by containing anything that's not valid.I'm not completely sure if it will work as expected, so don't be rushy on blaming the host for it if it doesn't.I am surprised by the 401 though. That should be working.You may want to take an alternative approach, if the host lets you use the HTTP extension, and that is to use http_send_status() to send the appropriate status code on the certain condition.

Link to comment
Share on other sites

You may want to take an alternative approach, if the host lets you use the HTTP extension, and that is to use http_send_status() to send the appropriate status code on the certain condition.
How would I do this? Have a php file with http_send_status() in it (is there anything to put in brackets)? Sorry, am a bit lost with this one...Son
Link to comment
Share on other sites

As the manual says, you need to put the status code in the brackets.But again, the host must have the HTTP extension installed and enabled or at least allow you to enable it yourself. It's very likely that as of now, it won't work. The HTTP extension is not one hosts usually install, the main reason being that the extension is simply not popular. And after all, any additional extensions that are enabled by default slow down performance a little, so it's in your interest that extensions you don't use don't get loaded into your space.

Link to comment
Share on other sites

As the manual says, you need to put the status code in the brackets.But again, the host must have the HTTP extension installed and enabled or at least allow you to enable it yourself. It's very likely that as of now, it won't work. The HTTP extension is not one hosts usually install, the main reason being that the extension is simply not popular. And after all, any additional extensions that are enabled by default slow down performance a little, so it's in your interest that extensions you don't use don't get loaded into your space.
I put
<?phphttp_send_status(401)?>

and get 'Fatal error: Call to undefined function http_send_status()'. So, as you thought it is not enabled. I had a look for entries into .htaccess, so I can test, but am a bit overwhelmed by the info about http status codes. Would I simply need to add 'Redirect 401 /e/401' to .htaccess?In addition, I created a faulty inner .htaccess and saw it working fine for error 500 (working fine meaning my custom error-500 showing). So, 403 and 500 are completely fine. 404 is fine with workaround from hosting company and 401 simply does not work... This makes 404 and 401 the problematic status codes for my custom error pages... This is really strange...Son

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...