Custom 404 inside the content area

This forum is for reporting bugs in Joomla!. Please don't report problems with extensions in here.
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 » Thu Jan 08, 2009 9:09 pm

leedsdoggod wrote: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
With my solution, the header still gives a 404 error code, so search engines would remove the pages from their index.

As for making it site unspecific, there is a way, something like you said, but I don't have enough time right now to code it.
Linux is half price today! Contact me to buy legitimate license keys.

zardiw
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Sun Jan 04, 2009 9:34 pm

Re: Custom 404 inside the content area

Post by zardiw » Tue Jan 27, 2009 5:41 pm

You have WAY too much time on your hands Amy....lol.......z

AmyStephen wrote:Arno -

You *are* using Joomla! differently than I am. You have said it many times, but now I get it. You push this little CMS to the virtual edge of the WWW! Me? I just try to use it.

I am humiliated to read your response and discover that I recommended you, a professional site developer, create a 404 page that could turn up in search results.

:-[

Allow me one more opportunity to redeem myself. I will re-read your brilliant, forward thinking post and look, again, at your example. Yes, SmashingMagazine, August 17, 2007. It's current. It's now. Something other professional web developers turn to for that little bit of something that noses them ahead of the pack. Sets 'em apart from the rest of us schmucks who have to think and creatively solve our problems.

One thing I *love* and *hate* about Smashing is how they have all of those examples stuffed into one page. Sometimes, I literally hear my computer chug through all of those bytes and links and images. On really large issues, I have (I SWEAR this is true) seen the lights dim, as energy normally used to heat and light my family home, is diverted for the purpose of guiding my geeky steps with breathtakingly brilliant leading edge approaches.

In the interest of time, I'll focus on the first example: 1. Appealing images. In simplistic terms I might understand, does that basically mean a pretty picture? Maybe one of those in a piece of content and a few modules scattered across the page, perhaps? Could one of those modules be a search box, as the very first example shows? Could a menu be offered with a list of options? Could the Latest News module be shared? Most read? List of authors? Heck. Gosh almighty. I can hardly contain my enthusiasm, but, dang it all, I think that might just work. NO REALLY! THAT MIGHT JUST WORK!

Dare I look at the second example: 2. Getting poetic I'll use their title - and apply my limited creativity (surely I can press out 17 syllables, right?):

404 error Haiku, by AmyStephen (aka Amy Stephen)

File not found? Oh no!
Whatever will I do now?
Try this page? Okay!

Darn it. Toe stubbed, again. Here we are, having come full circle right back to the challenge you so correctly raised when you sarcastically dismissed my solution as inadequate. The search results! Why, even 17 syllables can be discovered and sucked into a search results page by Joomla!'s vacuum powered discovery capabilities.

Ooh-ooh-ooooh! (hand raised!) (you are probably to young to remember Arnold Horshack.) What about using the LoadModule Plugin deceptively positioned inside of the article in order to display those sweet 17 syllable solutions on the 404 page?

Would that work, Arno?

I'm probably just giddy and overly optimistic, but I think we might be able to use these for mentioned methods to also 3. Communicate through emotions. as well as 4. Communicate through Irony. Scrolling ahead, and realizing, again, how you and I use Joomla! differently, I still cannot contain my optimism that, perhaps, even given the impossibility of the task you posed, that by harnessing the existing Joomla! framework as I described in my initial response, combined with these most recent ideas I respectfully submit for your discernment, ideas that I have suggested to you for implementing the very concepts in the article you identified as containing "some real creative 404 examples but whats more important, most of them have "inline" pages where navigation is still in place so people can just go on browsing your site", Arno, honestly, I believe we should be able to implement any of those fabulous ideas using Joomla!.

We are limited only by our imagination and are willingness to make things happen.

Amy

User avatar
roma64
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 110
Joined: Mon Feb 12, 2007 12:18 pm
Location: Reading, PA
Contact:

Re: Custom 404 inside the content area

Post by roma64 » Sat Feb 14, 2009 4:12 pm

I have been trying to setup a custom error page for some times but had a very hard time till I landed onto this thread and followed it which gave me a resolution with I have 2 small issues with that and would like assistance and I would greatly appreciate any help. Note that I use Google Webmaster Tool which is also important to me and I am not sure how the GWT will see this after making the changes (negatively or positively). I have copied the error.php to the root of my template and copied the following line right after the 'Restricted access' within the error.php file:

if (($this->error->code) == '404') {
header('Location: http://www.domain.com/index.php?option= ... icle&id=72');
exit;
}

Now, I use the Core Joomla SEF and would prefer using www.domain.com/404.html instead of the above ID but the only way to use the 404.html is to create a menu to that page and have it published, which is something I am not crazy about for it will be listed on my menu and sitemap (I have no problem with it showing on sitemap) and would like to avoid that. I also don't want my 404.html error to be found when using my site's search feature. Again, the above code works fine by me but I am also working on SEO, therefore, prefer the 404.html. Now, what I am looking for is the ability of not having to setup a menu for the 404 page and I also don't want to show up in the search result from my site. I thank everyone for this thread which helped me setting up my custom page and would appreciate any help with this. Thank you!

Sincerely yours!

Roma64
SimplerWebs

adaptds
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Mar 02, 2009 5:22 pm

Use the Google 404 Widget

Post by adaptds » Mon Mar 02, 2009 5:28 pm

Thanks to this thread, I was able to set up a clean 404 page and integrate the Google 404 widget.

It's now on my crm and issue tracking website. Give it a try with a bogus URL and you'll see the Google widget in action.

I'm a happy camper now guys. Thanks again for the help.
(J! 1.5.9)

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 Mar 06, 2009 8:32 am

openmtl wrote: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.
Somehow I couldn't download your error.php file that you attached. Can you email it to me instead? or should I just copy paste what you did and change everything to my domain and articles?

I am liking your solution especially that 500 error page and I am having that problem right now. I am currently using guyswithcable's solution with no problem at all except that it doesn't "cover" that 500 error.

I am a non-coder Joomla user so I know far less than anyone here but I do try to pickup some terms, languages, "laws" and stuffs. So with this solution, I will cover 404 error pages and 500 external error PLUS this works with whatever Google header thingy that you guys mentioned?

Xeonxz
Joomla! Intern
Joomla! Intern
Posts: 99
Joined: Sat Mar 25, 2006 1:01 pm

Re: Custom 404 inside the content area

Post by Xeonxz » Mon Mar 09, 2009 12:12 am

Just add the bold area in your error.php file. Don't forgot to change the url to your custom article.

<?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.yoursite.com/index.php?optio ... cle&id=121');
}
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
}
?>
Best Regards
Viktor
3on Webbyrå Stockholm http://www.3on.se
Flighton AB http://www.flighton.se

fox999
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Tue Aug 12, 2008 10:41 am

Re: Custom 404 inside the content area

Post by fox999 » Tue Apr 07, 2009 6:18 pm

Xeonxz wrote:Just add the bold area in your error.php file. Don't forgot to change the url to your custom article.

<?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.yoursite.com/index.php?optio ... cle&id=121');
}
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
}
?>
so with this code don`t we have any problem with google ?

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 » Wed Apr 08, 2009 9:39 am

fox999 wrote:so with this code don`t we have any problem with google ?
Correct. Google will receive a 404 error code, and will remove the page from its index. You can always check what code your server is sending with Telnet. Here's how:

We're going to make an HTTP request to your server
(Replace wherever.com in these steps with your own website.)
========
- Open a command prompt / terminal. (Start->Run->"cmd")
-Type "telnet wherever.com 80" (The 80 is the port we are connecting on. 80 is the HTTP port.)
(This is the Linux syntax, but the Windows version of Telnet should be pretty similar. Try "telnet /h" for help. Sorry, I don't have Windows, so I don't know it.)
-Once Telnet connects to the server, type the following:

Code: Select all

GET /noexist HTTP/1.1
host: wherever.com


(This requests wherever.com/noexist from the server, and should give you a 404 error.)
(Remember to hit return *twice* after the wherever.com)
-You'll probably have to scroll back up, but the first line the server sends you should be "HTTP/1.1 404 Not Found". If this is the case, congratulations, it works. If instead you get "HTTP/1.1 200 OK", there is a problem with your 404 page, and Google will not read this correctly. (Unless by some coincidence you happen to have a /noexist file or folder on your server ;) )

Good luck! :)

Edit:
One last note: If your installation is not in the root of your server (ie, you don't go to wherever.com, but something like wherever.com/joomla), you need to use something like "GET /joomla/noexist HTTP/1.1".
Linux is half price today! Contact me to buy legitimate license keys.

Pedantix
Joomla! Apprentice
Joomla! Apprentice
Posts: 40
Joined: Fri Jul 25, 2008 7:30 am

Re: Custom 404 inside the content area

Post by Pedantix » Tue Jun 16, 2009 5:54 pm

Xeonxz wrote:Just add the bold area in your error.php file. Don't forgot to change the url to your custom article.

<?php
...
if (($this->error->code) == '404') {
echo file_get_contents('http://www.yoursite.com/index.php?optio ... cle&id=121');
}
else
{...}
?>

I've tried this on J1.5.9 and I get the following error:

Code: Select all

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /usr/www/users/ell/ff/templates/sunshine/error.php on line 16

Warning: file_get_contents(http://ell.com/ff/?option=com_content&view=article&id=62:404) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /usr/www/users/ell/ff/templates/sunshine/error.php on line 16

Any suggestions on how to resolve this?

Thanks in advance!

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 Jun 20, 2009 9:21 pm

Pedantix wrote:I've tried this on J1.5.9 and I get the following error:

Code: Select all

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /usr/www/users/ell/ff/templates/sunshine/error.php on line 16

Warning: file_get_contents(http://ell.com/ff/?option=com_content&view=article&id=62:404) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /usr/www/users/ell/ff/templates/sunshine/error.php on line 16

Any suggestions on how to resolve this?

Thanks in advance!
That's not a Joomla problem, it's the way your PHP is configured. You can configure PHP to block access to opening URLs like they were files. If you're with a hosting provider, you should ask your server administrator if he can relax that restriction.
Linux is half price today! Contact me to buy legitimate license keys.

User avatar
revive1
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Sat Apr 12, 2008 1:41 am

Re: Custom 404 inside the content area

Post by revive1 » Wed Jul 08, 2009 7:57 pm

Ok.. for those of you who want something a little nicer looking than the standard joomla 404 AND don't want to code a new page to look like your template.. AND don't want the page to show in search results within your site... do this:

1) Copy the code below into a new file, name it 'error.php' and place it in your <joomla root>/templates/system/ folder (be sure to rename or backup the existing file named 'error.php' that is in there!

2) Change the email address to your own - this script will EMAIL YOU WHEN USERS GO TO IT! So, you can trouble shoot error page causes, etc.. you can always disable this feature by commenting out the section with the lines starting with '$message

3) Change the colors, add background images, etc within the CSS located within the HTML at the bottom of the page. It's very easy to make this look nice and similar, if not exactly, like your website!

4) Change the link names and location towards the bottom of the file to reflect the pages you want to offer your visitors - sitemap links are always good here people ;)

5) Enjoy having gotten rid of that ugly remnant of Joomla's 404 error page!

Cheers

Code: Select all


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

// change this to whatever email address you want the notifications to be sent to
$emailaddress = "[email protected]";

// only change this number if you plan on making other error pages.. eg. 403, 500, etc..
$errorNum = "404";

// message area - you can stop the emailing of error notices by commented out each of the lines below
        $errortime = (date("M d Y h:m:s"));
        $message .= $errorNum." Error Report\r\n\r\nA ".$errorNum." error was encountered by ".$_SERVER['REMOTE_ADDR'];
        $message .= " on $errortime.\r\n\r\n";
        $message .= "The URL which generated the 404 error is: \nhttp://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\r\n\r\n";
        $message .= "The referring page, if any, was:\n".$_SERVER['HTTP_REFERER']."\r\n\r\n";
        $message .= "The used client was:\n".$_SERVER['HTTP_USER_AGENT']."\r\n\r\n";
        $headers = "From: ".$emailaddress."\nDate: ".$errortime." +0100\n";
        $subject = "Error: ".$errorNum." from ".$_SERVER['HTTP_REFERER'];
        mail($emailaddress, $subject, $message, $headers);


// Here is the HTML output for the actual Error Page displayed to a user.. change it as needed

echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<title>404 Error - Page Not Found</title>	
	<style type="text/css">
	body {
		margin: 0;
		padding: 0;
		font: 12px/1.4 "Tahoma", Verdana, sans-serif;
		color:#555;
		background:#54992f;
	}
	div.image {
               width:700px; 
               height:250px;
               background:#fff;
               border:8px solid #345F1D;
               margin:40px auto;
               padding:50px 0 0 0;
               text-align:center;
}
	a:link, a:hover, a:visited {text-decoration:none;color:#749F45;}
	ul {list-style:none;width:350px;margin:100px auto 0;}
	ul li {float:left;margin-left:20px;}
	</style>
	</head>
	<body>
		<div class="image">
		<h1>404 Error - Page Not Found</h1>
		<div>Sorry, but the page you are looking for is either misspelled or no longer available.
		</div>
			<ul>Here are some links to get you where you want to go:
				<li><a href="http://example.com">Home</a></li>
				<li><a href="http://example.com/products">Online Store</a></li>
				<li><a href="http://example.com/products/something">Something</a></li>
				<li><a href="http://example.com/contact">Contact Us</a></li>
			</ul>
			<br />
		</div>	
		</body>
	</html> ';
?>

You can see a customize version of this same page. with background images added, etc.. here:

http://revivemarketing.org/joomla-errorpage.php
Don't worry.. I've turned the email notifications off, on this page :D


Hope this helps.. again, doesn't show in search results,. it's at least a base for you to start with for design.. and works with every Joomla install (J1.5 that is)

Cheers
My favorite web design/dev tools:
Rackspace Cloud Files + Cloud9 http://cloud9manager.com
24" iMac, MAMP Pro, Logitech MX Revolution, Coda, TextMate, Transmit, Snippley and Adobe CS4
For small ecommerce: http://nanao-cart.com

User avatar
steveorg
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 158
Joined: Tue Oct 30, 2007 5:17 pm
Location: The wrong coast

Re: Custom 404 inside the content area

Post by steveorg » Sun Jul 19, 2009 1:15 am

Pedantix wrote:I've tried this on J1.5.9 and I get the following error:

Code: Select all

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /usr/www/users/ell/ff/templates/sunshine/error.php on line 16

Warning: file_get_contents(http://ell.com/ff/?option=com_content&view=article&id=62:404) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /usr/www/users/ell/ff/templates/sunshine/error.php on line 16
Any suggestions on how to resolve this?

Thanks in advance!
I ran into the same problem so I went to my host for help as guywithcable suggested. They provided a simple fix. In the php.ini file in your root directory (create a new file if necessary), add this line:

Code: Select all

allow_url_fopen = On

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 Jul 19, 2009 4:24 am

revive1 wrote:You can see a customize version of this same page. with background images added, etc.. here:

http://revivemarketing.org/joomla-errorpage.php
Don't worry.. I've turned the email notifications off, on this page :D


Hope this helps.. again, doesn't show in search results,. it's at least a base for you to start with for design.. and works with every Joomla install (J1.5 that is)

Cheers
I'm assuming that when Joomla! include()s this page, it has already pushed a "HTTP/1.1 404 Not Found" header...

I bring this up because the page you linked to gives a 200 OK status. (But, it doesn't look like that's from a Joomla! installation.)

Am I correct?
Linux is half price today! Contact me to buy legitimate license keys.

User avatar
holdencreative
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Thu Oct 13, 2005 1:51 am
Location: Hamilton, ON
Contact:

Re: Custom 404 inside the content area

Post by holdencreative » Mon Jul 27, 2009 3:54 pm

Hello everyone,

I have created a summary of the primary 'Custom 404 Page' method discussed in this thread as a Joomla! Documentation Tutorial.

New Documentation Page:

http://docs.joomla.org/Tutorial:Create_ ... Error_Page

The only significant difference from the method described on the first page of this thread is that the tutorial suggests using a traditional Joomla! URL (non-SEF) in order to not require having a newly published menu item.

While this *may not be the best* method toward SEO and Joomla! it provides a single source solution to a common question on the forums.
Joomla! is an all-volunteer project. Be Kind.

Did you know that you can make almost any Joomla! site into an app? http://weeverapps.com

spadilla
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Tue Dec 05, 2006 11:01 pm

Re: Custom 404 inside the content area

Post by spadilla » Fri Aug 14, 2009 4:53 pm

steveorg wrote:
Pedantix wrote:I've tried this on J1.5.9 and I get the following error:

Code: Select all

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /usr/www/users/ell/ff/templates/sunshine/error.php on line 16

Warning: file_get_contents(http://ell.com/ff/?option=com_content&view=article&id=62:404) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /usr/www/users/ell/ff/templates/sunshine/error.php on line 16
Any suggestions on how to resolve this?

Thanks in advance!
I ran into the same problem so I went to my host for help as guywithcable suggested. They provided a simple fix. In the php.ini file in your root directory (create a new file if necessary), add this line:

Code: Select all

allow_url_fopen = On
Isn't " allow_url_fopen = On " something not recommended by Joomla security team?

User avatar
betweenbrain
Joomla! Guru
Joomla! Guru
Posts: 801
Joined: Wed Feb 28, 2007 5:40 am
Location: Connecticut, USA
Contact:

Re: Custom 404 inside the content area

Post by betweenbrain » Thu Dec 10, 2009 2:21 pm

holdencreative wrote: I have created a summary of the primary 'Custom 404 Page' method discussed in this thread as a Joomla! Documentation Tutorial.
Hi Holden,

Just to clarify, does this technique produce the proper headers?

Thanks,

Matt
Best,

Matt Thomas

User avatar
holdencreative
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Thu Oct 13, 2005 1:51 am
Location: Hamilton, ON
Contact:

Re: Custom 404 inside the content area

Post by holdencreative » Wed Feb 03, 2010 4:11 pm

Just to clarify, does this technique produce the proper headers?
It doesn't. But it's a simple & usable solution.

For a 'best practices' solution, see: http://docs.joomla.org/Custom_error_pages

..which does include information on building a proper 404.

For most Joomla! users, and most web sites in my opinion, usability is more important than standards. So, the document below is offered with the caveat that there are other, more 'proper' methods available.

http://docs.joomla.org/Tutorial:Create_ ... Error_Page

- Hope that's helpful info.
HC
Joomla! is an all-volunteer project. Be Kind.

Did you know that you can make almost any Joomla! site into an app? http://weeverapps.com

User avatar
torkil
Joomla! Guru
Joomla! Guru
Posts: 726
Joined: Wed Aug 24, 2005 9:34 am
Location: Rørvik, Norway
Contact:

Re: Custom 404 inside the content area

Post by torkil » Tue Mar 30, 2010 7:16 am

openmtl wrote: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 
 {
Great idea this. Now, all you need to do is modify the search plugin so that it does not return hits on your error pages. Easy enough.

rjdjohnston
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 102
Joined: Fri Dec 28, 2007 12:06 am
Contact:

Re: Custom 404 inside the content area

Post by rjdjohnston » Mon May 03, 2010 9:28 pm

Code: Select all

switch ($this->error->code) {
   case '404':   
      header('Location: '.$this->baseurl.'/index.php?option=com_content&view=article&id=#');
      exit;
      break;
   case '500':
      header('Location: '.$this->baseurl.'/index.php?option=com_content&view=article&id=#');
      exit;
      break;
   case '403':
      header('Location: '.$this->baseurl.'/index.php?option=com_content&view=article&id=#');
      exit;
      break;
}
Added "exit" as it did not work for me without. also using "$this->baseurl" for portability

User avatar
trevor4370
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 143
Joined: Fri Oct 14, 2005 5:26 am
Location: Bundaberg, Qld, Australia

Re: Custom 404 inside the content area

Post by trevor4370 » Wed May 19, 2010 6:04 am

I tried
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?optio ... cle&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?optio ... cle&id=YYY');
exit;

}

else
{
And
switch ($this->error->code) {
case '404':
header('Location: '.$this->baseurl.'/index.php?option=com_content&view=article&id=#');
exit;
break;
case '500':
header('Location: '.$this->baseurl.'/index.php?option=com_content&view=article&id=#');
exit;
break;
case '403':
header('Location: '.$this->baseurl.'/index.php?option=com_content&view=article&id=#');
exit;
break;
}
But i found that it does not handle the wrong file extention - eg index.pho, it will work for the wrong url /udex.php.

Example:

http://staceys.com.au/inddex.php (works)

http://staceys.com.au/index.phg (does not work)

See what i mean. Anybody know a work around?

User avatar
torkil
Joomla! Guru
Joomla! Guru
Posts: 726
Joined: Wed Aug 24, 2005 9:34 am
Location: Rørvik, Norway
Contact:

Re: Custom 404 inside the content area

Post by torkil » Wed May 19, 2010 8:25 am

I "solved" it this way:

Code: Select all

// templates/my_template/error.php

defined( '_JEXEC' ) or die( 'Restricted access' ); 

if (($this->error->code) == '404') {
    header("HTTP/1.0 404 Not Found");
    // load the article you want to use as your error page. Replace X with the article id.
    echo file_get_contents('http://example.com/index.php?option=com_content&view=article&id=X');
} else {
    require_once dirname(__FILE__).DS.'index.php';
}
This way the status code, 404, is set correctly, and you still get to show a complete, customizable article. Add an &Itemid=X to the URL if you want a menu item to be active too. This can be in a menu that is not shown on the page for instance, and allows you to load modules like you normally would too.

One catch here: If you don't want your error article to show up in the search results, you have to hack the search plugin too:

// plugins/search/content.php
On line 151, just below . ' WHERE ('.$where.')', add this line:

Code: Select all

. ' AND a.id != X'
(replace X with the article id like before)

Do the same thing below ' WHERE ('.$where.')' on lines around 184 and 225 too.

User avatar
trevor4370
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 143
Joined: Fri Oct 14, 2005 5:26 am
Location: Bundaberg, Qld, Australia

Re: Custom 404 inside the content area

Post by trevor4370 » Thu May 20, 2010 12:38 am

Refering to post Wed May 19, 2010
But i found that it does not handle the wrong file extention - eg index.pho, it will work for the wrong url /udex.php.

Example:

http://staceys.com.au/inddex.php (works)

http://staceys.com.au/index.phg (does not work)

See what i mean. Anybody know a work around?
I think I have found a simple workaround unsing the Error Page option in Cpanel. This might not be the best way, but I know this - it works for me - not sure about the Google search though, somebody with more knowledge might be able to answer this.

1. I set up all the error page in the Cpanel error pages with the following (simply a meta tag redirect to the article error page).

Code: Select all

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<META http-equiv="refresh" content="1;URL=http://www.yourdomain.com/index.php?option=com_content&view=article&id=30"> 
</head>
<body>
</body>
</html>code]

Examples:

http://www.regencyparkwarwick.com.au/new/inndex.php

http://www.regencyparkwarwick.com.au/new/index.pho

User avatar
bitstormweb
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Aug 20, 2010 2:19 pm
Location: Dayton, Oh
Contact:

Re: Custom 404 inside the content area

Post by bitstormweb » Tue Dec 07, 2010 8:11 pm

I know this conversation is old but i have my own solution that correctly reads as a 404 and displays in the Joomla 1.5 content area without any issues.. I based my error.php file off of the index.php file .. here's what I did:

The following code is in my template's error.php file, this is a modified Joomla index.php file that sets the 404 header at the top of it and then reads a plain html file to the buffer from code/errors.php .. I organize my template code into separate files, you could just have it load error_template.php or whatever you want. The important thing is that it doesn't parse PHP with this..

Another note is that I made this a basic template .. it looks for {CODE} and {MESSAGE} within your error template and replaces it with the error code and error message.. look for comments starting with 404 CODE to quick jump to my changes... also, this handles any kind of error, not just 404 ..

Hope this helps someone..

Ps. This method keeps the 404 out of the search engines and it requires no modifications to the Joomla core .. it just requires that you edit the 404 page manually in the template file.. I include this method in all of our templates at this point.

Code: Select all

<?php
// 404 CODE: Set the proper header
header("HTTP/1.0 404 Not Found");

$_REQUEST['template'] = "component";
/**
* @version		$Id: index.php 14401 2010-01-26 14:10:00Z louis $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2010 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.
*/

// Set flag that this is a parent file
define( '_JEXEC', 1 );

define('JPATH_BASE', dirname(__FILE__) );

define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;

/**
 * CREATE THE APPLICATION
 *
 * NOTE :
 */
$mainframe =& JFactory::getApplication('site');

/**
 * INITIALISE THE APPLICATION
 *
 * NOTE :
 */
// set the language
$mainframe->initialise();

#JPluginHelper::importPlugin('system');

// trigger the onAfterInitialise events
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
$mainframe->triggerEvent('onAfterInitialise');

/**
 * ROUTE THE APPLICATION
 *
 * NOTE :
 */
$mainframe->route();

// authorization
$Itemid = JRequest::getInt( 'Itemid');
$mainframe->authorize($Itemid);

// trigger the onAfterRoute events
JDEBUG ? $_PROFILER->mark('afterRoute') : null;
$mainframe->triggerEvent('onAfterRoute');


/**
 * DISPATCH THE APPLICATION
 *
 * NOTE :
 */
#$option = JRequest::getCmd('option');
#$mainframe->dispatch($option);

// trigger the onAfterDispatch events
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;
$mainframe->triggerEvent('onAfterDispatch');
/**
 * RENDER  THE APPLICATION
 *
 * NOTE :
 */
 /// OVERRIDE THE CONTENT HERE
$doc =& JFactory::getDocument();


// 404 CODE: Get the template and read in the errors.php file from the code subdirectory ( standard html, no php )
$err_content = file_get_contents("templates/".$mainframe->setTemplate."/code/errors.php");
$err_content = preg_replace("/{code}/", $this->error->code, $err_content);
$err_content = preg_replace("/{message}/", $this->error->message, $err_content);
$doc->setBuffer( $err_content, 'component', '' );

$mainframe->render();

// trigger the onAfterRender events
JDEBUG ? $_PROFILER->mark('afterRender') : null;
$mainframe->triggerEvent('onAfterRender');

/**
 * RETURN THE RESPONSE
 */
echo JResponse::toString($mainframe->getCfg('gzip'));
?>

drjjw
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Mon Jul 30, 2007 7:18 pm

Re: Custom 404 inside the content area

Post by drjjw » Fri Dec 10, 2010 10:38 am

bitstormweb

Your method is very elegant and works perfectly

It even works in a framework tempalte like RT Gantry where the Joomla documentation:

http://docs.joomla.org/Custom_error_pages

does not account for the differences in template organization. So your method is perfect for me:

1. Displays the entire template
2. Is not searchable
3. Returns the correct error codes.

Jordan

srchamp
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Feb 01, 2008 3:07 am

Re: Custom 404 inside the content area - Most Read module

Post by srchamp » Thu Dec 30, 2010 8:22 am

I've followed the documentation to create a Custom 404 and it works correctly except that when I use the Most Read module, the 404 comes to the top of the list. How can I stop this from happening?
I have also changed the code in the search plugin so it doesn't find the 404 article.

draggar
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Apr 11, 2011 10:51 pm

Re: Custom 404 inside the content area

Post by draggar » Mon Apr 11, 2011 10:54 pm

I'm having quite an issue with this now. All of my pages that should come up as a 404 are coming up with browser-specific error messages (NOT FOUND in FF, Oops! This link appears to be broken! in Chrome, etc.). I've also tried the (easy) version in the docs which did not help. :(

I've tried a few different options in this thread and non worked (this is also happening on different PCs so I am pretty sure it is not my computer).

Thoughts?

User avatar
garybrindley
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Apr 15, 2010 4:23 pm

Re: Custom 404 inside the content area

Post by garybrindley » Thu Apr 28, 2011 11:12 pm

Try this: http://extensions.joomla.org/extensions ... data/16481

It solves all the problems everyone is discussing in this thread. In a few seconds :-)
Gary Brindley
Qlue : Joomla Extensions That Just Work
http://www.qlue.co.uk

Betsie
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Sep 28, 2011 8:22 am

Re: Custom 404 inside the content area

Post by Betsie » Wed Sep 28, 2011 8:28 am

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

marye78
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Sep 22, 2011 6:16 am

Re: Custom 404 inside the content area

Post by marye78 » Tue Nov 08, 2011 3:50 am

Hi,

could you please let me know, where is the "restricted line"?
I'm using joomla 1.7.1 , try to have a custom 404 page.
Now, I copied the error.php file to my template directory but I don't know where should I copy the code?

I've attached my error.php code screenshot.
Thank you,
Maryam
You do not have the required permissions to view the files attached to this post.

marye78
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Sep 22, 2011 6:16 am

Re: Custom 404 inside the content area

Post by marye78 » Wed Dec 21, 2011 2:01 am

I think it's commercial. If I only download public version, is it useful?


Locked

Return to “Joomla! 1.5 Bug Reporting”