Penguination Project


Htaccess custom error page

Sometimes when your visitors browsing your page and your content was removed or deleted, they will see simple “not found” page or 404 error – not found message set by default with apache server. 

We will modify our server configuration file .htaccess and will show you how to design your custom error page. 

First we will create errorpage.html file , you can use your html or css methods to do that. 

create file called errorpage.html in your server root or create file on your desktop and upload it to your server, then edit. 

Type this code in your errorpage.html file , we didn’t define headers and body standards, but you can do it ,  any design could be used.

<div style=”width:500px;margin:0 auto;background:#eee;border:2px solid green”>

<div style-”padding:2em;color:#333″>

<h1>Error Occured</h1>

<p>

You reached page that doesn’t exists ….  <input type=”button” value=”back” onclick=”history.go(-1)”>

</p>

</div>

</div>

 

Save your errorpage.html , upload tou the root directory. 

Open .htaccess file and type the code below : 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /errorpage.html [L]

That’s it ! Save your .htaccess file , now go to any “not existing page” just type some mess in your browser url , you will see custom error file ! Congrats , now we know how  to deal with server errors manually. 

You can modify all possible server errors manually, here is solution :

ErrorDocument 400 /error/400.html
ErrorDocument 401 /error/401.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html

 

Good luck coder !

Post Metadata

Date
June 20th, 2009

Author
admin

Category


Leave a Reply