Joomla
Joomla Tips and Tricks
#49 - Custom Joomla 1.5 Error pages
|
|
| Monday, 27 October 2008 | ||||||||
#49 - Custom Joomla 1.5 Error pagesJoomla! 1.5 uses the error.php in templates/system to handle HTTP Status errors, including "403", "404", and "500" Errors. By tweaking the error.php file you can create your own error pages for these or other HTTP errors. Note that you cannot include modules or use <jdoc:include> statements in the error.php file. Overriding the System Error ResultsTo override the system error results, copy the templates/system/error.php file into your templates/<template-name> directory. When Joomla 1.5 finds a file there it will use the file in this template instead of the system error.php file. Using the new error.php file, style it such that it matches your template. Overriding the System StylingIf you want to change the styling, change the stylesheet: <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/error.css" type="text/css" /> to match the stylesheet of your template. Customizing Error MessagesTo create custom error message for each HTTP error, you'll need to add the following code in the error.php document. An example of this follows for error 500 (Internal Server Error) <?php if ($this->error->code = '500') { ?> <div id="errorboxheader">Internal Server Error</div> <div id="errorboxbody"> <p>The action you performed has resulted in an internal server error!</p> </div> </div> <?php } ?> Returning the correct HTTP status codeWhen a request is made for a page on your site, the server returns an HTTP status code in response to the request. Using this system of error pages, Joomla! will return a '200' i.e. 'the server successfully returned the page' for error pages. This is actually incorrect and may cause some problems, therefore you'll need some more tweaking to make sure the correct error codes are returned. This is done by adding the DOCTYPE tag, and Joomla will return the correct error code. <?php if ($this->error->code = '500') { header("HTTP/1.0 505 Internal Server Error"); } ?>With these tweaks, you now have designed your custom error pages ;)
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
||||||||
| Last Updated ( Monday, 27 October 2008 ) | ||||||||