howtothings.co.uk
How to use your own custom error pages on 000webhost - Printable Version

+- howtothings.co.uk (https://www.howtothings.co.uk)
+-- Forum: Computing (https://www.howtothings.co.uk/forumdisplay.php?fid=4)
+--- Forum: Website Development, Implementation and General Webmaster Support (https://www.howtothings.co.uk/forumdisplay.php?fid=9)
+--- Thread: How to use your own custom error pages on 000webhost (/showthread.php?tid=358)



How to use your own custom error pages on 000webhost - Mark - 09-09-2010

As some of you know i use 000webhost's free hosting services, (not to host this forum, before you get worried) for one or two of my smaller, personal sites and i think their service is top notch.

The only problem i came across was how they handled errors, 404s and such. By default they throw you off to their subdomain err.000webhost.com which is filled with ads and to be honest looks a mess and certainly not where you want people visiting your site to be going.

Here's a simple fix.

1. Make a file called "error.php", copy and paste the code below in to it, then save.

PHP Code:
<?php

$status 
$_SERVER['REDIRECT_STATUS'];
$codes = array(
        
403 => array('403 Forbidden''The server has refused to fulfill your request.'),
        
404 => array('404 Not Found''The document or file requested was not found.'),
        
405 => array('405 Method Not Allowed''The method specified in the Request-Line is not allowed for the specified resource.'),
        
408 => array('408 Request Timeout''Your browser failed to send a request in the time allowed by the server.'),
        
500 => array('500 Internal Server Error''The request was unsuccessful due to an unexpected condition encountered by the server.'),
        
502 => array('502 Bad Gateway''The server received an invalid response from the upstream server while trying to fulfill the request.'),
        
504 => array('504 Gateway Timeout''The upstream server failed to send a request in the time allowed by the server.')
        );
        
$title $codes[$status][0];
$message $codes[$status][1];
if (
$title == false || strlen($status) != 3) {
    
$message 'Please supply a valid status code.';
}

echo 
'<p><h1>' $title '</h1></p>' 
     
'<p>' $message '</p>'

 
?>


2. Create a new file and call it ".htaccess". If you create it and it doesn't show up then make one called "htaccess" without the full stop at the beginning and we'll go from there.

In this file simply put the following 3 lines, then save:

Code:
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php


Once you've got the two completed files you now need to upload them in to the "public_html" directory of your website. If before you missed out the full stop, rename it through the FTP manager so that it works.

Now, go to your domain eg. markwood.co.cc/doesntexist and you'll see your 404 page.