Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • anisjolly Friend
    #138624

    Do you hate it when you have broken links on your site or that dreaded error page with the 404 message appears and it looks nothing like your website???

    Well, today you’re going to learn how you can change all that by simply editing one piece of code in your Joomla site.

    For an example of what i’m talking about – just visit one of my sites (links in the signature) and at the end of the URL – just add some text to try and break my site – don’t worry all is in order – i’m pretty sure you won’t see the joomla error message. Once you’ve done that – return back here to continue with the modification tutorial.

    To help you with this, I’m going to share with you my own error page and I’ll highlight the code below you need to change in order to customize your 404 page.

    But before we start doing this, you need to create an article in the article manager. Call it whatever you want and put in whatever message you want your visitors to see when they come across the broken link / error page.

    Make sure you publish it the the Uncategorized section and category.

    Once you’ve done that – download my own error page (linked below) and then change the following code in the file you’ve just downloaded:

    /* Custom Error Page Mod Code */
    if (($this->error->code) == ‘404’) {
    echo file_get_contents(‘PUT URL FOR YOUR NEWLY CREATED ERROR ARTICLE HERE‘);
    }
    else
    {

    Your URL for your error article would look something like: http://www.anisjolly.co.uk/index.php?option=com_content&view=article&id=66 (if you’ve not setup SEF etc). If you have SEF enabled you’ll need to figure out the URL.

    Ok, we’ve nearly finished. Once you’ve done the amendment in the file, upload this amended file to the following folder in your joomla site:

    templates/system/

    It’s as simple as that – you’re all done. to test out the error page – just do what you tried to do on my site and see if your custom error page works!

    If you have any problems or would like me to do this for you – just leave a message below in this thread or send me a pm and i’ll be happy to help.


    1. error.zip
    jsliao Friend
    #293729

    Well technically, sites should never encounter 404 errors if it was well built but mistakes happens and its definately nicer to have a page like this than the default 404 error page.

    Great tip! Bookmarking this one!

    questbg Friend
    #293774

    Cheers anisjolly, awesome! I’m on it now 😀

    bennitos Friend
    #293793

    Nice one anisjolly,

    If there are users who have 404sef installed then you can do this with 404sef aswell.
    It has a simple editor screen where you can make your custom 404 message, or you can decide that instead of showing a 404 error to direct users to a existing article like your frontpage.

    On your 404sef control panel go to the main tab and look for “404 Page”
    Also look at the “404 page” tab where you can use the editor to create a custom msg.

    gray Friend
    #332533

    Very useful topic! I’m also thinking about creating an custom 404 page.
    BTW, here is some addition information http://docs.joomla.org/Custom_error_pages

    gray Friend
    #332713

    So, I’ve created the custom error page. I followed recommendations by Google and included:
    – home page link
    – Joomla main menu links
    – Joomla search field
    – Google Analytics tracking code

    All this was implemented with error.php and error.css files. Those interested could contact me via PM.

    power_on Friend
    #332724

    Woow.

    Thank you for sharing this.

    sdebaun Friend
    #338066

    Don’t hack the Joomla core code, future updates will overwrite your changes…

    Instead, simply put the error.php file in your chosen template directory. Joomla will find it and use it instead of the default file.

    For example, the new location will be at:
    yourwebsite.com/templates/yourtemplatename/error.php

    This is probably a better way of doing it…
    http://docs.joomla.org/Custom_error_pages

    I do have a question- how do you add the 404 error page (or whatever your article is called) without adding a menu item?

    skydebaun.com

    kutuloncat99 Friend
    #354404

    <em>@anisjolly 114969 wrote:</em><blockquote>Do you hate it when you have broken links on your site or that dreaded error page with the 404 message appears and it looks nothing like your website???

    Well, today you’re going to learn how you can change all that by simply editing one piece of code in your Joomla site.

    For an example of what i’m talking about – just visit one of my sites (links in the signature) and at the end of the URL – just add some text to try and break my site – don’t worry all is in order – i’m pretty sure you won’t see the joomla error message. Once you’ve done that – return back here to continue with the modification tutorial.

    To help you with this, I’m going to share with you my own error page and I’ll highlight the code below you need to change in order to customize your 404 page.

    But before we start doing this, you need to create an article in the article manager. Call it whatever you want and put in whatever message you want your visitors to see when they come across the broken link / error page.

    Make sure you publish it the the Uncategorized section and category.

    Once you’ve done that – download my own error page (linked below) and then change the following code in the file you’ve just downloaded:

    /* Custom Error Page Mod Code */
    if (($this->error->code) == ‘404’) {
    echo file_get_contents(‘PUT URL FOR YOUR NEWLY CREATED ERROR ARTICLE HERE‘);
    }
    else
    {

    Your URL for your error article would look something like: http://www.anisjolly.co.uk/index.php?option=com_content&view=article&id=66 (if you’ve not setup SEF etc). If you have SEF enabled you’ll need to figure out the URL.

    Ok, we’ve nearly finished. Once you’ve done the amendment in the file, upload this amended file to the following folder in your joomla site:

    templates/system/

    It’s as simple as that – you’re all done. to test out the error page – just do what you tried to do on my site and see if your custom error page works!

    If you have any problems or would like me to do this for you – just leave a message below in this thread or send me a pm and i’ll be happy to help.</blockquote>

    this is an other solution, replace all content of system/error.php with this
    <?php
    // no direct access
    defined( ‘_JEXEC’ ) or die( ‘Restricted access’ );

    /* Custom Error Page Mod Code */
    $urlLink=JURI::base().”/index.php?option=com_content&view=article&id=157″;
    $timeout=120;
    $CR = curl_init();
    curl_setopt($CR, CURLOPT_URL, “$urlLink”);
    curl_setopt($CR, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($CR, CURLOPT_TIMEOUT, $timeout);
    $response = curl_exec($CR);
    curl_close( $CR );
    $CR=explode(“</html>”,$CR);
    echo $CR[1].”</html>”;
    ?>

    jackzhu Friend
    #354411

    It is funny jokes i alway meet 404 for my website. By the way thank you for sharing this.

    nogrock Friend
    #384340

    Hi anisjolly,

    You can try using this Qlue Custom 404 component. It will work straight after install.

    It works like an article, you put in the html you want into your text editor and then your custom page will be displayed when there is an error. You can also add in modules into your custom pages and will also use your site’s template, saving you hours of editing the error.php file.

    You can download it free here: http://www.qlue.co.uk/joomla-extensions-15-a-16/joomla-custom-404-error-page.html

Viewing 11 posts - 1 through 11 (of 11 total)

This topic contains 11 replies, has 10 voices, and was last updated by  nogrock 13 years, 8 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum