Page 1 of 1

How do I create a custom 404 erro page? (solved)

Posted: Wed Feb 16, 2011 12:44 pm
by proveyourself
I've tried this tutorial but it's for 1.5 and it's not working?
Any tips?
Thank you.

Re: How do I create a custom 404 erro page?

Posted: Wed Feb 16, 2011 1:01 pm
by OOmNezar
Creating 404 page have many way. Try this to more understanding 404 page in Joomla.
http://docs.joomla.org/Custom_error_pages
or modified like : http://forum.joomla.org/viewtopic.php?f=428&t=593390

Re: How do I create a custom 404 erro page?

Posted: Wed Feb 16, 2011 1:15 pm
by proveyourself
I've made everthing from the first link but if I type something like "http://localhost:8888/joomla/foo" (this page doesn't exist) the error page is not called. I am redirected to the main page.

Re: How do I create a custom 404 erro page?

Posted: Wed Feb 16, 2011 1:41 pm
by OOmNezar
use header() in the first line http://php.net/manual/en/function.header.php and located/redirect to where ever you want

Re: How do I create a custom 404 erro page?

Posted: Wed Feb 16, 2011 3:08 pm
by proveyourself
No, no. You don't get what I said. I've placed a break point in error.php but it never reachs there.
Update: This link fix the issue.
Thank you.

Re: How do I create a custom 404 erro page? (solved)

Posted: Wed Nov 02, 2011 10:51 pm
by epidote
can't you just make a new item and menu and change the error.php from

Code: Select all

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

Code: Select all

if (!isset($this->error)) {
	
	$this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
	$this->debug = false; 
} else {
header('Location: /sorry-this-page-has-been-removed');
exit;
}
that seems to work?

Re: How do I create a custom 404 erro page? (solved)

Posted: Mon Jan 30, 2012 7:19 pm
by technoboyuk
The above code did not work for me, since upgrade to 2.5 my custom error page does not work, the code is different.

Would be useful if joomla reflected the new code in http://docs.joomla.org/Custom_error_pages

Created an uncategorised article, created a unpublished menu item
and copy error.php to template directory, then edited error.php to reflect link to the article that I created and put the url same as above, this did not work. Neither did using the full url.

deleted cache still did not work.

How do I create a custom 404 error page in Joomla 2.5

Posted: Mon Jan 30, 2012 11:01 pm
by technoboyuk
Found this in another post

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; ?>">
just change ID in the code above below to your own, it looks like this index.php?option=com_content&view=article&id=35


http://forum.joomla.org/viewtopic.php?p ... 2#p2729536

this appears to work fine for me, unless there is another way that is even better.

thank you duyet for the solution.

Re: How do I create a custom 404 erro page? (solved)

Posted: Wed Aug 08, 2012 5:08 am
by chiappa
Thank you technoboyuk that worked like a charm! And shame on Joomla for not updating their docs (plus the usual thanks...) :P

Re: How do I create a custom 404 erro page? (solved)

Posted: Sat Nov 10, 2012 6:25 pm
by kuknoor
Thanks technoboyuk for helping out and am requesting admin's and mod's of this forum to update the joomla docs with the above fix bcoz joomla docs is outdated

Re: How do I create a custom 404 erro page? (solved)

Posted: Sat Nov 10, 2012 10:15 pm
by marty69
Just wanted to ask the same question but I used search. That paid off :D

Re: How do I create a custom 404 erro page? (solved)

Posted: Mon Nov 19, 2012 8:36 pm
by raindelay
I used technoboyuk's answer and it worked. However, I am getting this error message on my custom 404 page:

Trying to get property of non-object in mysite/templates/mytemplate/index.php on line 13

Line 13 of the index.php file is: $params = $menu->getParams( $active->id );

Any ideas on how to fix this?

Re: How do I create a custom 404 erro page? (solved)

Posted: Thu Nov 29, 2012 10:11 pm
by dpeschio
Thank you! That worked like a charm - after spending hours trying to follow instructions on Joomla's website, then trying to edit the .htaccess. Finally this worked!

- check out my custom 404 page: http://ashevillealetrail.com/index.php/404-error/

Re: How do I create a custom 404 erro page? (solved)

Posted: Sun May 31, 2015 5:41 pm
by sandvelder
Hi, I have read the thread above, I have already done as described above prior to getting to this post, but still no happiness! :-(
I have several Joomla 3 websites running at a small variety of ISP's.
I want to get a custom 404-error message displayed on all my websites, but fail to get it right.
I have already created the Joomla article for the message, and created a link (/index.php?option=com_content&view=article&id=24) to display it.
That was the easy part.
The help I get from the Joomla tutorials is also simple to execute, but it does not work.
As I understand it, there is an error.php under /templates/system, which should be copied to /templates/[template name] and then edited.
The following line should be added under the line "defined('_JEXEC') or die;" :
if (($this->error->getCode()) == '404') {
header('Location: /index.php?option=com_content&view=article&id=24);
exit;
}
Having done the above, my websites return a variety of messages, all but the intended custom message.
What I can see from these messages are that they change according to the Apache Server the website is running on.
In other words, the server overrides the CMS.
Any ideas on getting a custom 404 message displayed?
URLs:
http://magicbrush.co.za
http://max-con.co.za
http://it.doxadeo.co.za
http://raymonddye.co.za
http://gustavgreyling.co.za
http://dynamiclifeskill.co.za
http://skolierxpress.co.za
http://vilnard.co.za

Re: How do I create a custom 404 erro page? (solved)

Posted: Sun May 31, 2015 7:40 pm
by jessicasclound9
dpeschio wrote:Thank you! That worked like a charm - after spending hours trying to follow instructions on Joomla's website, then trying to edit the .htaccess. Finally this worked!

- check out my custom 404 page: http://ashevillealetrail.com/index.php/404-error/

looks good :)

Re: How do I create a custom 404 erro page? (solved)

Posted: Mon Jun 01, 2015 2:29 am
by chiappa
sandvelder wrote:Hi, I have read the thread above, I have already done as described above prior to getting to this post, but still no happiness! :-(
Are you not using "Search Engine Friendly URLs"?

Code: Select all

<?php
defined('_JEXEC') or die;

if (($this->error->getCode()) == '404') {
header('Location: /404');
exit;
}
?>
source here

Re: How do I create a custom 404 erro page? (solved)

Posted: Mon Jun 01, 2015 6:42 am
by sandvelder
Thank you, but as I have said before, I have tried the above already. My 404 page does not show.

Re: How do I create a custom 404 erro page? (solved)

Posted: Mon Jun 01, 2015 8:02 am
by chiappa
Are you missing an apostrophe there (see below)? And have you tried using a SEF instead?

Code: Select all

header('Location: /index.php?option=com_content&view=article&id=24');

Re: How do I create a custom 404 erro page? (solved)

Posted: Mon Jun 01, 2015 8:19 am
by sandvelder
Hi, sharp of you to catch that! But alas, no, I did not miss it in the error.php file.

Re: How do I create a custom 404 erro page? (solved)

Posted: Mon Jun 01, 2015 6:57 pm
by sandvelder
OK, I found the solution. But what I cannot grasp is the load of BS I had to go through to get to final solution.

I edited the empty .htaccess file and added the following line:
ErrorDocument 404 /index.php?option=com_content&view=article&id=24

Why does nobody mention this in these forums? I found this detail in a forum for Apache Web Servers:
http://www.4webhelp.net/tutorials/misc/errors.php