Page 2 of 4

Re: Custom 404 inside the content area

Posted: Thu Aug 14, 2008 3:33 am
by derred
Hi,

I have been reading this thread and I have tried all suggested but I can't seem to make it work.

Basically from my understanding is we load a module inside our error.php page. But still, patches of codes on the above makes me a lil bit out of place. Anyway I am Joomla beginner so please hang with me.

So this is the default error.page

Code: Select all

<?php
/**
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<!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->code ?> - <?php echo $this->title; ?></title>
	<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/system/css/error.css" type="text/css" />
</head>
<body>
	<div align="center">
		<div id="outline">
		<div id="errorboxoutline">
			<div id="errorboxheader"><?php echo $this->error->code ?> - <?php echo $this->error->message ?></div>
			<div id="errorboxbody">
			<p><strong><?php echo JText::_('You may not be able to visit this page because of:'); ?></strong></p>
				<ol>
					<li><?php echo JText::_('An out-of-date bookmark/favourite'); ?></li>
					<li><?php echo JText::_('A search engine that has an out-of-date listing for this site'); ?></li>
					<li><?php echo JText::_('A mis-typed address'); ?></li>
					<li><?php echo JText::_('You have no access to this page'); ?></li>
					<li><?php echo JText::_('The requested resource was not found'); ?></li>
					<li><?php echo JText::_('An error has occurred while processing your request.'); ?></li>
				</ol>
			<p><strong><?php echo JText::_('Please try one of the following pages:'); ?></strong></p>
			<p>
				<ul>
					<li><a href="<?php echo $this->baseurl; ?>/index.php" title="<?php echo JText::_('Go to the home page'); ?>"><?php echo JText::_('Home Page'); ?></a></li>
				</ul>
			</p>
			<p><?php echo JText::_('If difficulties persist, please contact the system administrator of this site.'); ?></p>
			<div id="techinfo">
			<p><?php echo $this->error->message; ?></p>
			<p>
				<?php if($this->debug) :
					echo $this->renderBacktrace();
				endif; ?>
			</p>
			</div>
			</div>
		</div>
		</div>
	</div>
</body
</html>
So from all the above patches of codes, where and how should I include the codes/lines to have the custom module inside my error.php?

For example this code

Code: Select all

    <?php
       foreach (JModuleHelper::getModules('main_menu') as $module)  {
           $module = JModuleHelper::renderModule($module, array('style' => 'xhtml', 'id' => 'section-box'));
           echo $module;
       }
    ?>
I am bit confuse on the overall codes. So how exactly this works. Like say I make a custom_html module and positioned it as content1. How do translate that into those codes.

Thank you in advance. Please advise.

Re: Custom 404 inside the content area

Posted: Fri Aug 15, 2008 1:06 am
by guysmiley
HI derred,

Using error.php became to convoluted for me so I ended up moving over to sh404 (available in JED).

Re: Custom 404 inside the content area

Posted: Fri Aug 15, 2008 3:20 am
by derred
Hi guysmiley,

are u using Joomla 1.5? I used it once but if you read my previous post its way too buggy and I bet shumisha is very busy at the mean time so I guess I would look forward a stable version of sh404sef.

So there is no one could help with the how to load module with those codes?

please advise me.

Re: Custom 404 inside the content area

Posted: Fri Aug 15, 2008 4:30 am
by derred
I have read this thread couple of times and turned out I noticed the last 2 posts on the 1st page mentioning loading module isn't a great idea for some google webmaster or whatever reason it has.

So basically this thread doesn't have a conclusion.. just yet. Maybe the best way is like someone has suggested here; creating a component that specially handle 404. Which for now the only option by 3rd-party is sh404.

Thank you for spending time reading my posts.

Please advise thank you.

Re: Custom 404 inside the content area

Posted: Mon Aug 18, 2008 1:54 am
by guysmiley
Hi derred,

I've been using sh404 for J1.5 for over a month now and have not noticed any serious bugs.

Re: Custom 404 inside the content area

Posted: Mon Aug 18, 2008 8:54 am
by derred
guysmiley,

Thanks for replying. At the moment I managed to downgrade to older version of sh404sef that works with mosets pagination and other stuff. The only problem I have now is I can't login as registered member when I am on Mosets Tree page.

When sh404 turned OFF, I can login regardless Joomla's CORE turned ON or OFF. I would say I feel a lil bit better now after downgrading, since sh404 latest build was so buggy especially with Mosets Tree component.

Another problem with sh404sef is when I set it not to override sef ext, it messed up the whole site with blank page. I assume it supposes to use Joomla's core sef instead messing the whole site up.

What are u using on your site anyway? Like what is your components?

Re: Custom 404 inside the content area

Posted: Mon Aug 18, 2008 1:06 pm
by ircmaxell
Well, why not use the core?

Re: Custom 404 inside the content area

Posted: Tue Aug 19, 2008 3:54 am
by derred
ircmaxell wrote:Well, why not use the core?
I did use the core. Well if you read my previous post I was asking on how to have module loaded on 404 page. I always wanted a more flexible 404 pages that I can customize accordingly compared to joomla's default.

But there is no response and that leaves me no option. I mentioned how I prefer Joomla's default better. Since I have no bug when using Core compared to sh404sef.

I have read and tried all the codes on this thread but none works (my fault since I don't really know codes). There were no specific how-to or tutorial on how to do custom 404 page, so right now I have to live with sh404 and some of its bugs.

Re: Custom 404 inside the content area

Posted: Wed Aug 20, 2008 4:06 pm
by stateoftheheart
I'm curious what to do as well for a custom 404 page. I'm using Joomla 1.5.6. Has anyone attempted this with the current platform.

I've created a custom page:

http://www.mysite.com/404.html

and I see that the 'error.php' file exists within the 'libraries/joomla/error' directory.

I don't have a duplicate testing server set-up just yet so I'm proceeding with extreme caution.

Has anyone attempted this with 1.5.6 and obtained the results they were seeking?

Please share...

Re: Custom 404 inside the content area

Posted: Sat Aug 23, 2008 11:41 pm
by mcsmom
If you look at joomla.org
say

http://www.joomla.org/sillycat.htm

you will see just a lovely error page. It doesn't use a module, but it does have links to search and home
I think it is simple yet extremely effective.

Re: Custom 404 inside the content area

Posted: Tue Aug 26, 2008 6:55 am
by rutja76
Hi!
mderksen wrote:If you want to do this correct... do it the following way:

Code: Select all

if (($this->error->code) == '404') {
header("HTTP/1.0 404 Not Found");
header('Location: ' . $this->baseurl . 'your-404-page.html', false ,404);
exit;
Read the PHP manual header function:
void header ( string $string [, bool $replace [, int $http_response_code ]] )
Unfortunately the code you pasted (using Joomla 1.5.6) doesn't work. I have the standard code for redirecting to the 404 custom page, that is

Code: Select all

if (($this->error->code) == '404') {
header('Location: ' . $this->baseurl . 'your-404-page.html');
exit;
This works, but the header returns 200 (cross-checked with Google Webmaster Tools). If I add either

Code: Select all

if (($this->error->code) == '404') {
header('Location: ' . $this->baseurl . 'your-404-page.html', true, 404);
exit;
or the solution you mentioned, I have a 404 header, but I don't get the redirection to the 404 custom page (a blank page appears instead). So at the moment the custom redirect works, but I get a 200 response instead of the desired 404.

Cheers,
Rutja76

Re: Custom 404 inside the content area

Posted: Tue Aug 26, 2008 7:47 pm
by mcsmom
I've been working on this and I think probably the key is to send the header when you get to the error page rather than when you leave the sending page.

Also, it makes more sense to use the framework error and header stuff e.g

http://dev.joomla.org/component/option, ... =jresponse

http://dev.joomla.org/component/option, ... es:jerror/

Re: Custom 404 inside the content area

Posted: Tue Aug 26, 2008 8:36 pm
by rutja76
mcsmom wrote:I've been working on this and I think probably the key is to send the header when you get to the error page rather than when you leave the sending page.
Yes, I agree. After all, the 200 Page found comes from the error page, not from the error.php.
mcsmom wrote: Also, it makes more sense to use the framework error and header stuff e.g

http://dev.joomla.org/component/option, ... =jresponse

http://dev.joomla.org/component/option, ... es:jerror/
This goes beyond my capabilities. Do you mean that at present it is not possible to make an error redirect page show a 404 in the header? Previosly I checked the link you posted that links to a 404 page on joomla.org, and that does give a 404 header. Is the website using a SEO component? Otherwise how is that possible?

Cheers,

Re: Custom 404 inside the content area

Posted: Tue Aug 26, 2008 10:01 pm
by derred
Doesn't mean to interrupt the flow here but I found 404sef component could do the trick as well.

Try it out, if it stills doesn't cater your needs, then uninstall it.

Re: Custom 404 inside the content area

Posted: Tue Aug 26, 2008 11:43 pm
by mcsmom
No it's a true error page using a custom error.php.

Re: Custom 404 inside the content area

Posted: Wed Aug 27, 2008 5:13 am
by rutja76
mcsmom wrote:No it's a true error page using a custom error.php.
Do you know then how to customise the error.php in order to get a 404 code? The solutions I have explained above don't work.

Cheers,

Re: Custom 404 inside the content area

Posted: Wed Aug 27, 2008 8:01 am
by guywithcable
Just thought I'd chime in here. I use a different method in my error.php. I use an echo of the html of the error page. This keeps the script from redirecting and changing the browser's address bar. (So the user can fix a typo.) It returns a 404 http code. I checked using telnet. And it's also compatible with Google's Webmaster Tool Enhance 404 Page. Unfortunately though, your error page still shows up in search results.

1. Make an error page as a content page.
2. Use the address of the page in a "echo file_get_contents('http://www.jrpsocal.com/main/error-404-page-not-found');" style. (If you want a shorter URL like mine, make a menu called "Uncategorized" or something, then add the error page to it. Don't publish the menu's module.)
3. Put it in your error.php like this (so it will return other errors the normal way):

Code: Select all

<?php
/**
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );


if (($this->error->code) == '404') {
  echo file_get_contents('http://www.jrpsocal.com/main/error-404-page-not-found');
} 
else
{
?>
<!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->code ?> - <?php echo $this->title; ?></title>
	<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/system/css/error.css" type="text/css" />
</head>
<body>
	<div align="center">
		<div id="outline">
		<div id="errorboxoutline">
			<div id="errorboxheader"><?php echo $this->error->code ?> - <?php echo $this->error->message ?></div>
			<div id="errorboxbody">
			<p><strong><?php echo JText::_('You may not be able to visit this page because of:'); ?></strong></p>
				<ol>
					<li><?php echo JText::_('An out-of-date bookmark/favourite'); ?></li>
					<li><?php echo JText::_('A search engine that has an out-of-date listing for this site'); ?></li>
					<li><?php echo JText::_('A mis-typed address'); ?></li>
					<li><?php echo JText::_('You have no access to this page'); ?></li>
					<li><?php echo JText::_('The requested resource was not found'); ?></li>
					<li><?php echo JText::_('An error has occurred while processing your request.'); ?></li>
				</ol>
			<p><strong><?php echo JText::_('Please try one of the following pages:'); ?></strong></p>
			<p>
				<ul>
					<li><a href="<?php echo $this->baseurl; ?>/index.php" title="<?php echo JText::_('Go to the home page'); ?>"><?php echo JText::_('Home Page'); ?></a></li>
				</ul>
			</p>
			<p><?php echo JText::_('If difficulties persist, please contact the system administrator of this site.'); ?></p>
			<div id="techinfo">
			<p><?php echo $this->error->message; ?></p>
			<p>
				<?php if($this->debug) :
					echo $this->renderBacktrace();
				endif; ?>
			</p>
			</div>
			</div>
		</div>
		</div>
	</div>
</body>
</html>
<?php
}
?>

Re: Custom 404 inside the content area

Posted: Wed Aug 27, 2008 8:15 am
by rutja76
guywithcable wrote:Just thought I'd chime in here. I use a different method in my error.php. I use an echo of the html of the error page.
Yes! That made the trick. Cheers!

Re: Custom 404 inside the content area

Posted: Thu Aug 28, 2008 11:31 am
by revive1
Beautiful! May be searchable... but reality is... most people won't click it in the search results, and if they do, at least the 404 is FINALLY presentable.

In regards to Joomla!, I am THOROUGHLY impressed with it's progress, the teams commitment and devotion to a great CMS. I hope, and look forward, to the polishing of the 404 page, and more importantly, a faster, lighter loading design in future releases. Props!

P.S. the easiest way to find the URL to the search page you just created is to go to your site, search for 404 and viola'... there is the address you need to insert into the code offered above :)
Cheers!

Re: Custom 404 inside the content area

Posted: Fri Aug 29, 2008 4:45 am
by revive1
Ran into small problem when just copying 'the portion of the file that looked different from the orig' :)

You MUST copy/paste the whole code provided above!

:)

Enjoy

Re: Custom 404 inside the content area

Posted: Fri Aug 29, 2008 10:23 am
by JamieShields
Arno & Amy - Get a room!

Re: Custom 404 inside the content area

Posted: Mon Sep 08, 2008 11:17 am
by evdboogaard
Thanks guywithcable!!!

Cheers,
Erwin

P.S. Any suggestions how to integrate a redirection to a custom page when someone is not registered (or logged in)?

Re: Custom 404 inside the content area

Posted: Tue Sep 09, 2008 9:42 pm
by evdboogaard
I've posted my solution for all custom error messages here:
http://forum.joomla.org/viewtopic.php?f ... 1#p1410961

Re: Custom 404 inside the content area

Posted: Tue Sep 30, 2008 7:54 pm
by cvoogt
Based on the Joomla documentation I created an "error.php" and put it in /templates/system/.
Here are the contents:

Code: Select all

<?php
defined('JPATH_BASE') or die();
echo file_get_contents(JURI::root().'/index.php?option=com_content&view=article&id=23');
?>
Just add in your custom URL for the error page's article. This works like a charm for me with 1.5.7.

Re: Custom 404 inside the content area

Posted: Wed Oct 01, 2008 12:34 am
by yourhoop
Tried a few of the suggestions listed is this post...the suggestion just above my post was the fastest (I just deleted the code in the existing /templates/system/error.php and pasted the code above...dropped in my URL and it works like a champ. Thanks...

Re: Custom 404 inside the content area

Posted: Wed Oct 01, 2008 3:05 am
by cvoogt
No problem.
I hope in a next release we might see a way to manage error pages using Joomla natively, the way Artio JoomSef and other components do. I have tried using htaccess to set custom error documents but couldn't get that to work, which is why I used the method above.

Re: Custom 404 inside the content area

Posted: Tue Oct 07, 2008 9:23 pm
by kdcpelt
Hello, This long string goes beyond my experience in Joomla, but going back to the original 4-stop process...I have followed the instructions and I cannot get the 404 page to show up. I'm getting a "Forbidden Access (Flooding)" error message. I have no idea what is causing this.

I edited the file called "error.php" in:

public_html/joomla/templates/system/

then I created a Section called "Error Pages" and a Category called "Error Pages" and an Artcile called "Having Trouble?" with an alias of "404error"

ergo, the path should be http://www.waysideyouth.org/joomla/Erro ... error.html

RIGHT?

Re: Custom 404 inside the content area

Posted: Tue Oct 07, 2008 9:30 pm
by mcsmom
kdcpelt wrote:Hello, This long string goes beyond my experience in Joomla, but going back to the original 4-stop process...I have followed the instructions and I cannot get the 404 page to show up. I'm getting a "Forbidden Access (Flooding)" error message. I have no idea what is causing this.

I edited the file called "error.php" in:

public_html/joomla/templates/system/

then I created a Section called "Error Pages" and a Category called "Error Pages" and an Artcile called "Having Trouble?" with an alias of "404error"

ergo, the path should be http://www.waysideyouth.org/joomla/Erro ... error.html

RIGHT?

No, make a menu link and get a proper path from that.

Re: Custom 404 inside the content area

Posted: Tue Oct 07, 2008 9:58 pm
by cvoogt
Right - use Joomla's internal URL instead of the SEF URL - so in this format:

/index.php?option=com_content&view=article&id=23

or
/index.php?option=com_content&view=article&id=23&Itemid=78

the easiest way to do this is to create a menu link (in a hidden menu .. I always use topmenu for that), link it to an article view of your error page, save the menu item, and then copy its URL and paste it into error.php in templates/system/ as described.

Re: Custom 404 inside the content area

Posted: Tue Oct 07, 2008 10:07 pm
by evdboogaard
SEF url works for me too...