Custom 404 inside the content area

This forum is for reporting bugs in Joomla!. Please don't report problems with extensions in here.
kdcpelt
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Wed May 07, 2008 3:25 am

Re: Custom 404 inside the content area

Post by kdcpelt » Tue Oct 07, 2008 10:10 pm

Thank you for that tip. I'd mistakenly duplicated a menu and therefore the menu did not automatically create the module. I had misaligned the two and of course, it didn't know where to get the content. I went back and created the menu from scratch which generated a Module. Then I created the menu link, published it to test it out, then published it only to SPECIAL. Works now. Thanks so much!

cvoogt
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 211
Joined: Wed Sep 27, 2006 1:10 am
Location: Sterling, VA, USA
Contact:

Re: Custom 404 inside the content area

Post by cvoogt » Tue Oct 07, 2008 10:29 pm

SEF URLs will work, but I personally use Joomla's internal URL in case I ever need to turn SEF URLs off or switch SEF URL systems.

ivytony
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Fri Dec 16, 2005 12:33 am

Re: Custom 404 inside the content area

Post by ivytony » Sat Oct 18, 2008 5:14 am

wow, Amy's solution works flawlessly and beautifully for me. A happy Joomla 1.5 user! :D :D

User avatar
ChiefGoFor
Joomla! Champion
Joomla! Champion
Posts: 5614
Joined: Tue Sep 13, 2005 12:22 am
Location: Omaha, Nebraska, USA
Contact:

Re: Custom 404 inside the content area

Post by ChiefGoFor » Thu Oct 23, 2008 5:02 pm

My Solution:

Create a file in your template's folder called "error.php" (same directory as your template's index.php file). The following is the contents of that file:

Code: Select all

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

global $mainframe;

$mainframe->redirect($this->baseurl.'index.php');
?>
Then, after index.php, put the rest of the URL. Make sure that any known error page has 301s set up in your htaccess file for better handling and SEO.
Joomla! ...because open source matters
"Try to answer two questions for every one question you ask." - Me

evdboogaard
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Thu Nov 09, 2006 11:38 pm
Location: Netherlands

Re: Custom 404 inside the content area

Post by evdboogaard » Thu Oct 23, 2008 5:25 pm

Will this send the correct header?

mandm
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Jun 23, 2008 2:47 pm

Re: Custom 404 inside the content area

Post by mandm » Sat Nov 01, 2008 5:18 am

Hi can someone please list an accurate step by step solution to this problem
It will be really helpful to know if and how someone got the solution to this problem

Please!

User avatar
guywithcable
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Fri Jul 04, 2008 2:05 am
Location: San Diego, USA
Contact:

Re: Custom 404 inside the content area

Post by guywithcable » Sun Nov 02, 2008 5:39 pm

mandm wrote:Hi can someone please list an accurate step by step solution to this problem
It will be really helpful to know if and how someone got the solution to this problem

Please!
Read my post earlier in the thread.
Linux is half price today! Contact me to buy legitimate license keys.

User avatar
mirandapablog
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Jul 05, 2008 12:09 am

Re: Custom 404 inside the content area

Post by mirandapablog » Thu Nov 13, 2008 5:16 pm

I've been testing the error.php and joomla 1.5.7 set 404 response, so we don't need to set 404 response

Code: Select all

<?php
if ($this->error->code = '404') {
   header("HTTP/1.0 404 Not Found");
} ?>


cheers

renocho
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Aug 12, 2008 6:42 am

Re: Custom 404 inside the content area

Post by renocho » Sun Nov 16, 2008 10:28 am

cvoogt wrote: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.
Doesn't work for me (1.5.6).

User avatar
mcsmom
Joomla! Exemplar
Joomla! Exemplar
Posts: 7897
Joined: Thu Aug 18, 2005 8:43 pm
Location: New York
Contact:

Re: Custom 404 inside the content area

Post by mcsmom » Sun Nov 16, 2008 1:04 pm

If you are at 1.5.6 you have bigger problems than customizing your error page.
So we must fix our vision not merely on the negative expulsion of war, but upon the positive affirmation of peace. MLK 1964.
http://officialjoomlabook.com Get it at http://www.joomla.org/joomla-press-official-books.html Buy a book, support Joomla!.

derred
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Fri Feb 15, 2008 2:07 am

Re: Custom 404 inside the content area

Post by derred » Tue Nov 18, 2008 9:53 pm

hey all,

reading this whole thread back and forth, I personally think that one of those solutions that works and have minimal disadvantages would be guywithcable's solution.

All I am asking here other than searchable 404 page, what's the downside I should expect going with guywithcable's solution of handling 404 page?

Thank you in advance and please advise.

derred
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Fri Feb 15, 2008 2:07 am

Re: Custom 404 inside the content area

Post by derred » Thu Nov 20, 2008 10:18 am

Is it possible to return 500 page to custom page?

User avatar
mcsmom
Joomla! Exemplar
Joomla! Exemplar
Posts: 7897
Joined: Thu Aug 18, 2005 8:43 pm
Location: New York
Contact:

Re: Custom 404 inside the content area

Post by mcsmom » Thu Nov 20, 2008 6:33 pm

You return whatever error number is used in the raiseError.
So we must fix our vision not merely on the negative expulsion of war, but upon the positive affirmation of peace. MLK 1964.
http://officialjoomlabook.com Get it at http://www.joomla.org/joomla-press-official-books.html Buy a book, support Joomla!.

User avatar
guywithcable
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Fri Jul 04, 2008 2:05 am
Location: San Diego, USA
Contact:

Re: Custom 404 inside the content area

Post by guywithcable » Fri Nov 21, 2008 8:34 pm

derred wrote:All I am asking here other than searchable 404 page, what's the downside I should expect going with guywithcable's solution of handling 404 page?

Thank you in advance and please advise.
No other downsides. ;)
Linux is half price today! Contact me to buy legitimate license keys.

derred
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Fri Feb 15, 2008 2:07 am

Re: Custom 404 inside the content area

Post by derred » Fri Nov 21, 2008 8:46 pm

guywithcable,

thank you for the reply. I have now convert my site to Joomla's core SEF. :)

anyway, when I changed to joomla SEF, I notice my title (on the browser) says "mysite - home" or "mysite - blog". When I change or remove mysite from global config it gives me " - home" or " - blog"

Is there any way I could possible remove the "mysite" all together? Since this is not happening before with sh404sef.

Please advise.

User avatar
guywithcable
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Fri Jul 04, 2008 2:05 am
Location: San Diego, USA
Contact:

Re: Custom 404 inside the content area

Post by guywithcable » Fri Nov 21, 2008 9:45 pm

Derred,

What version of Joomla are you using?
Linux is half price today! Contact me to buy legitimate license keys.

derred
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Fri Feb 15, 2008 2:07 am

Re: Custom 404 inside the content area

Post by derred » Fri Nov 21, 2008 10:55 pm

guywithcable wrote:Derred,

What version of Joomla are you using?
Joomla 1.5.8 ftw :)

User avatar
guywithcable
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Fri Jul 04, 2008 2:05 am
Location: San Diego, USA
Contact:

Re: Custom 404 inside the content area

Post by guywithcable » Sat Nov 22, 2008 12:10 am

derred wrote:Joomla 1.5.8 ftw :)
I'm not sure. :(

I'm using Joomla's SEF, and it's not doing that.
Linux is half price today! Contact me to buy legitimate license keys.

derred
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Fri Feb 15, 2008 2:07 am

Re: Custom 404 inside the content area

Post by derred » Sat Nov 22, 2008 12:32 am

guywithcable wrote:
derred wrote:Joomla 1.5.8 ftw :)
I'm not sure. :(

I'm using Joomla's SEF, and it's not doing that.
Oh it is joomla's SEF.

http://www.pembaris.com

fmontrelay
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Sun Nov 16, 2008 1:57 pm

Re: Custom 404 inside the content area

Post by fmontrelay » Wed Nov 26, 2008 9:25 am

My god, this is all too difficult for me. :(
Is there a simple way to manage the way error 404 page will look?
I mean without getting into the code etc...

Thanks

amg99
Joomla! Explorer
Joomla! Explorer
Posts: 264
Joined: Sun Jul 02, 2006 5:14 am

Re: Custom 404 inside the content area

Post by amg99 » Sat Dec 13, 2008 10:48 pm

Jick wrote:Is it possible to render 404 in the content area of the site where normally the not found article would render?

Right now there is the error.php in the templates/system dir which can be customized by putting a copy in your own template dir but this file doesn't allow module calls etc.

I have no problem with a separate error file but I would like to recreate the template there with menu's and search so when someone types a wrong url and gets a 404 he or she can just keep on browsing the site or use the search function.

It would be even more easy to get a customizable error message via component so there is no need to recreate the template in error.php.

Anyone ideas?

Arno
Hi,

I thought I'd share the solution I found in creating a custom 404 error page with top and footer menus and a search field.

To render the topmenu module, I used the code from cullenlinn
http://forum.joomla.org/viewtopic.php?p ... 4#p1331654:

Code: Select all

<div id="topmenu">
$module = new stdClass();
$module->module = 'mod_mainmenu';
$module->params = "menutype=topmenu\nshowAllChildren=1";
echo JModuleHelper::renderModule($module);
</div>
The parameter "menutype" specifies which mod_mainmenu should be displayed.

Also, since I'm using a mootools drop down menu (based on this wonderful tutorial by ah72 http://forum.joomla.org/viewtopic.php?f=466&t=295837), I have to always show sub-menu items.

I did that with the parameter "showAllChildren" which is set to yes.

you can also use this method when you want to display your other menus.


To be able to display the search form:

Code: Select all

		<form action="index.php" method="post">
			<div class="search">
				<input name="searchword" id="mod_search_searchword" maxlength="20" alt="Search" class="inputbox" size="30" value="search..." onblur="if(this.value=='') this.value='search...';" onfocus="if(this.value=='search...') this.value='';" type="text">	<input value="Search" class="button" onclick="this.form.searchword.focus();" type="submit">
            </div>
			<input name="task" value="search" type="hidden">
			<input name="option" value="com_search" type="hidden">
		</form>

hope this helps.

wineblue2
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Wed Nov 05, 2008 3:24 pm

Re: Custom 404 inside the content area

Post by wineblue2 » Mon Dec 22, 2008 3:11 pm

:eek: I am running J1.5.8 on PHP5.2.5 and I have read this topic up and down. I keep hearing how Joomla is the most awesome CMS for people who know nothing about programming but this thread may as well be written in Greek. The programees language in here is way over my head and from some of the other responses I have read I'm not the only one who feels this way. Is there not any Joomla pros who are fluent enough with this who can write a post in Layman's terms so that anyone can understand how to create an internal 404 page either with or without sh404sef? The code posts are great IF you already know what to do with them and where to put them but the average novice doesn't have a clue what this code means, where it goes, or why!

The Wine Nut

User avatar
mcsmom
Joomla! Exemplar
Joomla! Exemplar
Posts: 7897
Joined: Thu Aug 18, 2005 8:43 pm
Location: New York
Contact:

Re: Custom 404 inside the content area

Post by mcsmom » Mon Dec 22, 2008 4:05 pm

The best thing for a novice is:

Avoid the common problems that lead to 404 pages.
Don't try to be tricky. Make the access levels for your menu items match the access levels for your content.
If you unpublish something remove all links to it.
Keep the access levels of your section, category and article hierarchies consistent.
If you remove something permanently set up a permanent redirect.

In other words all of the same things you would do with a basic html only site.
So we must fix our vision not merely on the negative expulsion of war, but upon the positive affirmation of peace. MLK 1964.
http://officialjoomlabook.com Get it at http://www.joomla.org/joomla-press-official-books.html Buy a book, support Joomla!.

fmontrelay
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Sun Nov 16, 2008 1:57 pm

Re: Custom 404 inside the content area

Post by fmontrelay » Mon Dec 22, 2008 5:19 pm

Actually, my hosting system (hostway) does that very well

wineblue2
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Wed Nov 05, 2008 3:24 pm

Re: Custom 404 inside the content area

Post by wineblue2 » Mon Dec 22, 2008 7:49 pm

mcsmom wrote:The best thing for a novice is:

Avoid the common problems that lead to 403 pages.
Don't try to be tricky. Make the access levels for your menu items match the access levels for your content.
If you unpublish something remove all links to it.
Keep the access levels of your section, category and article hierarchies consistent.
If you remove something permanently set up a permanent redirect.

In other words all of the same things you would do with a basic html only site.
OK well search engine results weigh in heavy on the traffic I receive and considering that within 2 weeks after posting this site as live I was in the top 10 SE returns on Google for Renewable energy systems. Obviously I would like that to continue. So the use of SEF and in particularly sh404sef along with xmap became required, but in so doing now I am facing this issue with the 404 pages which do not appear to be as easily customized as they are advertised. BTW my site is http://www.globalteamdirect.net if you would care to take a look at what I am talking about.
Basically what I am trying to achieve is an 403 unauthorized access from within the site template so the visitor knows they need to register on the web site before they will be granted access. Anything else and they will just hink the site is not functioning correctly and leave.

User avatar
mcsmom
Joomla! Exemplar
Joomla! Exemplar
Posts: 7897
Joined: Thu Aug 18, 2005 8:43 pm
Location: New York
Contact:

Re: Custom 404 inside the content area

Post by mcsmom » Tue Dec 23, 2008 1:05 am

That's what I mean. If you want to do tricky, then yes you are going to have to learn how to use register to read more, create over rides and so on.
So we must fix our vision not merely on the negative expulsion of war, but upon the positive affirmation of peace. MLK 1964.
http://officialjoomlabook.com Get it at http://www.joomla.org/joomla-press-official-books.html Buy a book, support Joomla!.

leedsdoggod
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Oct 02, 2007 8:27 pm

Re: Custom 404 inside the content area

Post by leedsdoggod » Thu Jan 08, 2009 9:25 am

Hello Everyone (especially guywithcable)

I have 4 questions at the end of this e-mail

Firstly my experience is fairly basic, I have a solid grounding in HTML, have fiddled in css, and know nothing about php

I've utilised guywithcable's solution from page 2 of this thread to great effect but was still a bit worried about the non-existant pages still being indexed in search engines like google. I am assuming that it will not recognise it as a 404 error and wont therefore remove the old pages from the index (I think I am right in saying this, If I am wrong then let me know). This is a problem as I am doing a migration from 1.0.15 so will be getting a lot of 404's coming up and would really like them removed.

In the meantime I have come up with a workaround and am wondering if it is a good way of doing it. After implementing guywithcable's solution I did a view source and saved the file to index.htm. I then changed the source of this file to change the robots tag to <meta name="robots" content="noindex, follow" /> to stop it indexing. I then uploaded this file to a new /errors directory on my server and re-pointed guywithcable's bit of code in error.php accordingly.

So my questions are
1) Is my assumption that google would not remove 404 error pages with guywithcable's initial work correct?
2) Will my workaround have the effect of removing the non-existent pages from search engines indexes?
3) Will there be any other side effects with my workaround?
and totally unrelated
4) how can I change guywithcables initial work to make it non site specific. I imagine it will involve changing the line echo file_get_contents('http://www. to having something to do with baseurl or site or something.

Thanks very much

Andy

fmontrelay
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Sun Nov 16, 2008 1:57 pm

Re: Custom 404 inside the content area

Post by fmontrelay » Thu Jan 08, 2009 11:39 am

It is extremely frustrating to initiate a thread and to read increasingly un-understandable replies....

openmtl
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Jan 08, 2009 5:38 pm

Re: Custom 404 inside the content area

Post by openmtl » Thu Jan 08, 2009 5:59 pm

I have a Joomla 1.5.7 site on PHP 5.2.5 on a server in which the PHP get_file_contents() is forbidden to be used (I know of a number of hosting companies that do that and it can really mess you up unless you know about cURL - those that block PHP get_file_contents() seem to allow cURL) so this is what I did.....

Step 1) Copy the system error.php file to my template directory (just about everyone says to start with that step anyway),

Step 2) Open that (now in template area) error.php file and add the following php code,

Code: Select all

function curl_get_file_contents($URL)
    {
        $c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $URL);
		curl_setopt($c, CURLOPT_USERAGENT, "CURL ERROR PAGE");
        $contents = curl_exec($c);
        curl_close($c);

        if ($contents) return $contents;
            else return FALSE;
    }

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

header("HTTP/1.0 404 Not Found");
echo curl_get_file_contents('http://www.mydomain.tld/index.php?option=com_content&view=article&id=XXX');
exit;

}
else if (($this->error->code) == '500') {

header("HTTP/1.0 500 Internal Server Error");
echo curl_get_file_contents('http://www.mydomain.tld/index.php?option=com_content&view=article&id=YYY');
exit;

}

else 
 {
<snip the rest of the OLD error.php file > etc etc you get the idea.

Look closely and you will see I am effectively curling some URLS i.e. fetching them and echoing them to the client. What URLs do I use ?

They are any URL on your site actually but what I did was to make them custom to me with humorous comments on what went wrong and a link to the home page and to the search page as follows,

Step A) Create a Section e.g. "Technical Error Pages"
Step B) Create 1 category per each error type. Why ? Well when you display an article you don't want the "Next > and < Prev" appearing at the bottom of the page going to the next article in the category so by only having 1 article per error per category there is no Next/Prev navigation.
Step C) Create 1 article for 404 page and assign it the Section of e.g."Technical Error Pages" a category of e.g. "Category Error 404" and 1 article for the 500 page with the section of "Technical Error Pages" a category of e.g. "Category Error 500" . repeat for other errors though I only ever get 404 and 500.
Step D) Save the articles and record their page IDs. Remember these and put them into the source code above (where I have put XXX and YYY).
Step E) Test. To test 404 is easy. Just put in a junk article number. To test for 500 errors try to logon but then mangle the URL you are at by messing with the view e.g. view=loginfdfdfgdgd rather than view=login ...Unknown component views trigger a 500 error.

This works for me and the headers are correct 404 and 500 headers so any smart search engines hopefully will invalidate that search page entry and age out obsolete pages.

openmtl
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Jan 08, 2009 5:38 pm

Re: Custom 404 inside the content area

Post by openmtl » Thu Jan 08, 2009 7:11 pm

...and here is my error.php because a working example is easy to understand. Same issue sapply - swap domain name to your domain name, swap XXX,YYY to your article IDs. It's zipped because can't post php file (why do I feel so dirty posting zip files to a Forum ? ;) ;)
You do not have the required permissions to view the files attached to this post.


Locked

Return to “Joomla! 1.5 Bug Reporting”