Custem Error Page - The best way?

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
Jeroen07
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Mon Jan 28, 2008 1:46 pm

Custem Error Page - The best way?

Post by Jeroen07 » Thu Jan 26, 2012 11:09 pm

Hello,

I'm making a "start version" of Joomla which I use to code all my websites with. In this start package all the components that i often use are configured right already (RSForm, Xmap, SIG Plus,...)

Now, one of the things that I would want to set-up correctly is the custom error page. In the pas i've used QLUE 404 and other components but that didn't always turned out good when the template was coded.

What i'd prefer to do is to make a custom error page as a normal article. I would do it this way:

1. Set up the article
2. Edit .htaccess:

Code: Select all

ErrorDocument 404 /page-not-found

Am i doing it the correct way like this? For SEO purposes it's important that this page returns the correct "Not Found" code. Otherwise search engines might index pages (www.domain.com/ddsldsdsds) that doesn't exist...


Please some advice...

User avatar
duyet
Joomla! Guru
Joomla! Guru
Posts: 935
Joined: Wed Sep 21, 2011 8:21 pm
Location: on earth
Contact:

Re: Custem Error Page - The best way?

Post by duyet » Fri Jan 27, 2012 6:15 am


Jeroen07
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Mon Jan 28, 2008 1:46 pm

Re: Custem Error Page - The best way?

Post by Jeroen07 » Fri Jan 27, 2012 11:55 am

Thanks. But how can you do this in Joomla 2.5? Step 4 doesn't work anymore, can't find the restricted access line...
Modify error.php to Redirect 404 Errors to your 404 Article

Edit the error.php file as follows, adding the code below immediately under the 'restricted access' line:

if (($this->error->code) == '404') {
header('Location: /index.php?option=com_content&view=article&id=75');
exit;
}

If you are using Joomla 1.6/1.7, use this detection code instead:

if (($this->error->getCode()) == '404') {

Replace the location information (index.php?option..) with the URL from the menu item you created.

User avatar
duyet
Joomla! Guru
Joomla! Guru
Posts: 935
Joined: Wed Sep 21, 2011 8:21 pm
Location: on earth
Contact:

Re: Custem Error Page - The best way?

Post by duyet » Fri Jan 27, 2012 2:33 pm

Try this:

Code: Select all

<?php
/**
 * @package		Joomla.Site
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;
if (!isset($this->error)) {
	$this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
	$this->debug = false;
}
//get language and direction
$doc = JFactory::getDocument();
$this->language = $doc->language;
$this->direction = $doc->direction;

if (($this->error->getCode()) == '404') {
    header('Location: /index.php?option=com_content&view=article&id=35');
    exit;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
Don't forget to change the id!!!

User avatar
CptDecker
Joomla! Ace
Joomla! Ace
Posts: 1047
Joined: Mon Feb 27, 2006 3:00 am
Location: New York
Contact:

Re: Custem Error Page - The best way?

Post by CptDecker » Fri Jan 27, 2012 2:50 pm

This can also be done with a SEO component like sh404SEF. We use it on our site and it works really well... Feel free to try it out http://www.totalhosting.com/test

It is also a great SEO tool and has a security component as well.
CptDecker

Total Hosting -- Professional Joomla Web Hosting
http://www.totalhosting.com/Web-Hosting/Joomla.html

Jeroen07
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Mon Jan 28, 2008 1:46 pm

Re: Custem Error Page - The best way?

Post by Jeroen07 » Fri Jan 27, 2012 3:43 pm

Jeroen07 wrote:Thanks. But how can you do this in Joomla 2.5? Step 4 doesn't work anymore, can't find the restricted access line...
Modify error.php to Redirect 404 Errors to your 404 Article

Edit the error.php file as follows, adding the code below immediately under the 'restricted access' line:

if (($this->error->code) == '404') {
header('Location: /index.php?option=com_content&view=article&id=75');
exit;
}

If you are using Joomla 1.6/1.7, use this detection code instead:

if (($this->error->getCode()) == '404') {

Replace the location information (index.php?option..) with the URL from the menu item you created.
http://www.conversal-test.be/start/sdsdcccv

That doesn't work (i've changed the ID...)

Jeroen07
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Mon Jan 28, 2008 1:46 pm

Re: Custem Error Page - The best way?

Post by Jeroen07 » Sat Jan 28, 2012 8:44 pm

can you check this please?

Jeroen07
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Mon Jan 28, 2008 1:46 pm

Re: Custem Error Page - The best way?

Post by Jeroen07 » Sat Feb 25, 2012 3:25 pm

Anyone? This is quite important, the response code is not good on these pages...

treehugger73
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 114
Joined: Sun Apr 27, 2008 11:07 am

Re: Custem Error Page - The best way?

Post by treehugger73 » Sat Apr 28, 2012 10:29 am

Thanks duyet, worked for me.

valdivij
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Jul 26, 2012 12:08 am

Re: Custem Error Page - The best way?

Post by valdivij » Thu Jul 26, 2012 4:47 pm

Just want to add the way suggested by duyet got the custom 404 page working for me (Joomla! 2.5.)

One small detail that is driving me crazy, though, is that right before the actual custom article (from index.php?option=com_content&view=article&id=xx) the word "Articles" is being displayed.

This has got to be somehow related to the uncategorized menu item (step 2 of creating custom 404 error page), as this is set to Menu Item Type: Articles >> Single Article.

I've tried changing all sorts of settings within the menu and article items, and even slightly modified the error.php file, to no avail.

Oh, well. It's not a big deal; as the custom 404 page is working. It's mostly annoying not being able to get rid of this extra line. So, if anybody has any suggestion, I'd be more than happy to try it.

Cheers!

treehugger73
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 114
Joined: Sun Apr 27, 2008 11:07 am

Re: Custem Error Page - The best way?

Post by treehugger73 » Thu Jul 26, 2012 6:11 pm

Open en-GB.ini from the language folder and delete "Articles" from JGLOBAL_ARTICLES="Articles"
so it looks like this; JGLOBAL_ARTICLES=""

dhrubaa
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Aug 22, 2011 9:38 pm

Re: Custem Error Page - The best way?

Post by dhrubaa » Mon Aug 20, 2012 5:41 pm

Hi I have been trying to create my custom error page. This is how my code looks at this moment. But it still does not display my custom article. Can any on eplease help?

<?php
/**
* @package Joomla.Site
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;}
{
if (!isset($this->error))
$this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
$this->debug = false;
}

//get language and direction
$doc = JFactory::getDocument();
$this->language = $doc->language;
$this->direction = $doc->direction;

if (($this->error->code) == '404') {
header('Location: http://www.bestgiftstokolkata.com/index ... cle&id=114');
exit;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
<head>
<title><?php echo $this->error->getCode(); ?> - <?php echo $this->title; ?></title>
<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/system/css/error.css" type="text/css" />
<?php if ($this->direction == 'rtl') : ?>
<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/system/css/error_rtl.css" type="text/css" />
<?php endif; ?>
</head>
<body>

<div class="error">
<div id="outline">
<div id="errorboxoutline">
<div id="errorboxheader"><?php echo $this->error->getCode(); ?> - <?php echo $this->error->getMessage(); ?>

</div>

<div id="errorboxbody">

<p><strong><?php echo JText::_('JERROR_LAYOUT_NOT_ABLE_TO_VISIT'); ?></strong></p>
<ol>
<li><?php echo JText::_('JERROR_LAYOUT_AN_OUT_OF_DATE_BOOKMARK_FAVOURITE'); ?></li>
<li><?php echo JText::_('JERROR_LAYOUT_SEARCH_ENGINE_OUT_OF_DATE_LISTING'); ?></li>
<li><?php echo JText::_('JERROR_LAYOUT_MIS_TYPED_ADDRESS'); ?></li>
<li><?php echo JText::_('JERROR_LAYOUT_YOU_HAVE_NO_ACCESS_TO_THIS_PAGE'); ?></li>
<li><?php echo JText::_('JERROR_LAYOUT_REQUESTED_RESOURCE_WAS_NOT_FOUND'); ?></li>
<li><?php echo JText::_('JERROR_LAYOUT_ERROR_HAS_OCCURRED_WHILE_PROCESSING_YOUR_REQUEST'); ?></li>
</ol>
<p><strong><?php echo JText::_('JERROR_LAYOUT_PLEASE_TRY_ONE_OF_THE_FOLLOWING_PAGES'); ?></strong></p>

<ul>
<li><a href="<?php echo $this->baseurl; ?>/index.php" title="<?php echo JText::_('JERROR_LAYOUT_GO_TO_THE_HOME_PAGE'); ?>"><?php echo JText::_('JERROR_LAYOUT_HOME_PAGE'); ?></a></li>
</ul>

<p><?php echo JText::_('JERROR_LAYOUT_PLEASE_CONTACT_THE_SYSTEM_ADMINISTRATOR'); ?>.</p>
<div id="techinfo">
<p><?php echo $this->error->getMessage(); ?></p>
<p>
<?php if ($this->debug) :
echo $this->renderBacktrace();
endif; ?>
</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

http://www.bestgiftstokolkata.com

treehugger73
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 114
Joined: Sun Apr 27, 2008 11:07 am

Re: Custem Error Page - The best way?

Post by treehugger73 » Tue Aug 21, 2012 5:55 am

I can see your error page so it's all working now dhrubaa

dhrubaa
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Aug 22, 2011 9:38 pm

Re: Custem Error Page - The best way?

Post by dhrubaa » Tue Aug 21, 2012 5:58 am

It probably is! Thank you :)


Locked

Return to “General Questions/New to Joomla! 2.5”