-->

Mengatasi Error Page dengan file htaccess

7:43 AM

Mungkin anda pernah mengunjungi beberapa situs ketika anda klik ternyata error page, dan error page tersebut beranimasi , pasti anda kesal sekaligus heran. Sebagai contoh disini, anda tidak asing dengan kaskus, ketika koneksi lambat maka kaskus akan error dengan pesan kaskus kepenuhan.. Inilah yang disebut error 500. Namun, tidakkah anda heran cara membuat error page dalam suatu website? Untuk membuat error page ini, sangatlah mudah, anda hanya butuh 2 file atau lebih. Namun, file yang terpenting adalah file yang bernamakan ".htacces" pada suatu direktori di webserver anda. Bagaimanakah caranya ? simak ya :P


Tambahkan file .htacces pada /public_html(folder utama dimana website disimpan) hosting kamu. Isi file tersebut dengan kode berikut:
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php

Kemudian tambahkan juga file error.php pada /public_html hosting kamu. Isikan file tersebut dengan kode berikut ini :

<?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>';
?>

Bisa juga anda menggunakan file html, hanya anda butuh modifikasi kode sedikit..

Nah,Teman juga bisa memakai file HTML lainnya untuk membuat suatu Error Page (tanpa menggunakan Error.php yang tertera di atas) bagaimana caranya ? edit isi dari .htacces tersebut, dan rubah tulisan "error.php" dengan nama html sesuka teman, misalkan teman ingin menggunakan "error.htm" , teman cukup merubah tulisan di dalam htacces diatas seperti ini :

ErrorDocument 403 /error.htm
ErrorDocument 404
/error.htm
ErrorDocument 500 /error.htm

Cukup mudah bukan cara membuat errorpage menggunakan htaccess, selamat berkreasi gan...