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

Everything to do with Joomla! 2.5 templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
proveyourself
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Thu Oct 15, 2009 2:12 pm

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

Post by proveyourself » Wed Feb 16, 2011 12:44 pm

I've tried this tutorial but it's for 1.5 and it's not working?
Any tips?
Thank you.
Last edited by proveyourself on Wed Feb 16, 2011 4:15 pm, edited 1 time in total.

User avatar
OOmNezar
Joomla! Ace
Joomla! Ace
Posts: 1869
Joined: Mon Sep 07, 2009 3:18 am

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

Post by OOmNezar » Wed Feb 16, 2011 1:01 pm

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
coffee & smoke just fine
OOm Nezar

proveyourself
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Thu Oct 15, 2009 2:12 pm

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

Post by proveyourself » Wed Feb 16, 2011 1:15 pm

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.

User avatar
OOmNezar
Joomla! Ace
Joomla! Ace
Posts: 1869
Joined: Mon Sep 07, 2009 3:18 am

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

Post by OOmNezar » Wed Feb 16, 2011 1:41 pm

use header() in the first line http://php.net/manual/en/function.header.php and located/redirect to where ever you want
coffee & smoke just fine
OOm Nezar

proveyourself
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Thu Oct 15, 2009 2:12 pm

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

Post by proveyourself » Wed Feb 16, 2011 3:08 pm

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.

User avatar
epidote
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Fri Jul 20, 2007 1:37 am
Contact:

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

Post by epidote » Wed Nov 02, 2011 10:51 pm

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?

technoboyuk
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Sat Oct 04, 2008 4:41 pm

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

Post by technoboyuk » Mon Jan 30, 2012 7:19 pm

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.

technoboyuk
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Sat Oct 04, 2008 4:41 pm

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

Post by technoboyuk » Mon Jan 30, 2012 11:01 pm

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.

User avatar
chiappa
Joomla! Intern
Joomla! Intern
Posts: 82
Joined: Wed Oct 26, 2011 6:53 pm
Location: Mostly Northeast Asia
Contact:

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

Post by chiappa » Wed Aug 08, 2012 5:08 am

Thank you technoboyuk that worked like a charm! And shame on Joomla for not updating their docs (plus the usual thanks...) :P

User avatar
kuknoor
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 101
Joined: Wed Sep 01, 2010 6:18 am
Location: hyderabad,india
Contact:

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

Post by kuknoor » Sat Nov 10, 2012 6:25 pm

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
Srinivas Kuknoorpalli,
Freelance Jommla & Drupal Developer in hyderabad.
http://www.antar.in

marty69
Joomla! Apprentice
Joomla! Apprentice
Posts: 39
Joined: Sun Aug 07, 2011 10:02 am
Location: Milky Way

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

Post by marty69 » Sat Nov 10, 2012 10:15 pm

Just wanted to ask the same question but I used search. That paid off :D

raindelay
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Fri Nov 11, 2011 4:52 pm

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

Post by raindelay » Mon Nov 19, 2012 8:36 pm

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?

dpeschio
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Tue Nov 09, 2010 1:55 am

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

Post by dpeschio » Thu Nov 29, 2012 10:11 pm

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/

User avatar
sandvelder
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Sep 08, 2011 10:03 am
Location: Pretoria, South Africa
Contact:

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

Post by sandvelder » Sun May 31, 2015 5:41 pm

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
Francois Barnard
https://sandvelder.com
Pretoria

User avatar
jessicasclound9
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Sun May 24, 2015 10:06 pm

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

Post by jessicasclound9 » Sun May 31, 2015 7:40 pm

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 :)
Last edited by jessicasclound9 on Mon Jun 01, 2015 7:02 am, edited 1 time in total.

User avatar
chiappa
Joomla! Intern
Joomla! Intern
Posts: 82
Joined: Wed Oct 26, 2011 6:53 pm
Location: Mostly Northeast Asia
Contact:

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

Post by chiappa » Mon Jun 01, 2015 2:29 am

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

User avatar
sandvelder
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Sep 08, 2011 10:03 am
Location: Pretoria, South Africa
Contact:

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

Post by sandvelder » Mon Jun 01, 2015 6:42 am

Thank you, but as I have said before, I have tried the above already. My 404 page does not show.
Francois Barnard
https://sandvelder.com
Pretoria

User avatar
chiappa
Joomla! Intern
Joomla! Intern
Posts: 82
Joined: Wed Oct 26, 2011 6:53 pm
Location: Mostly Northeast Asia
Contact:

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

Post by chiappa » Mon Jun 01, 2015 8:02 am

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');

User avatar
sandvelder
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Sep 08, 2011 10:03 am
Location: Pretoria, South Africa
Contact:

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

Post by sandvelder » Mon Jun 01, 2015 8:19 am

Hi, sharp of you to catch that! But alas, no, I did not miss it in the error.php file.
Francois Barnard
https://sandvelder.com
Pretoria

User avatar
sandvelder
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Sep 08, 2011 10:03 am
Location: Pretoria, South Africa
Contact:

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

Post by sandvelder » Mon Jun 01, 2015 6:57 pm

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
Francois Barnard
https://sandvelder.com
Pretoria


Locked

Return to “Templates for Joomla! 2.5”