Custom error page returns 302 instead of 404

General questions relating to Joomla! 1.5 There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
nugepcua
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Mon Nov 02, 2009 2:53 pm

Custom error page returns 302 instead of 404

Post by nugepcua » Sun Oct 24, 2010 12:24 pm

I followed this guide to make 404 page based on my current template:
http://docs.joomla.org/Tutorial:Create_ ... Error_Page

Upper part of my current error.php looks like this:
Code:
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if (($this->error->code) == '404') {
header('Location: index.php?option=com_content&view=article&id=2762');
exit;
}
?>


The only problem I have is that web server returns 302 HTTP status code instead of 404.

I found this fix, but couldn't make it work:
http://docs.joomla.org/Custom_error_pag ... tatus_Code

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


Need little advise on how accommodate this code in my error.php
Thanks!

nugepcua
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Mon Nov 02, 2009 2:53 pm

Re: Custom error page returns 302 instead of 404

Post by nugepcua » Tue Oct 26, 2010 8:48 am

anyone?

User avatar
leolam
Joomla! Master
Joomla! Master
Posts: 20652
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ Germany/ S'pore/Bogor/ North America
Contact:

Re: Custom error page returns 302 instead of 404

Post by leolam » Tue Oct 26, 2010 9:19 am

Code: Select all

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if (($this->error->code) == '404') {
header('Location: index.php?option=com_content&view=article&id=159');
exit;
}
?>
works for me fine

Please post a link to your site (not in pmb)?

Leo 8)
Joomla's #1 Professional Services Provider:
#Joomla Professional Support: https://gws-desk.com -
#Joomla Specialized Hosting Solutions: https://gws-host.com -

nugepcua
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Mon Nov 02, 2009 2:53 pm

Re: Custom error page returns 302 instead of 404

Post by nugepcua » Fri Oct 29, 2010 10:53 am

"Visually" custom error page works. It just only returns wrong error code.

See what error code I get from Google webmaster tools when I visit non-existent page:
HTTP/1.1 302 Found
Date: Fri, 29 Oct 2010 10:49:52 GMT
Server: Apache/2.2.3 (CentOS)

How to force it return 404 error code instead?

nugepcua
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Mon Nov 02, 2009 2:53 pm

Re: Custom error page returns 302 instead of 404

Post by nugepcua » Wed Nov 10, 2010 5:20 pm

please help

yaksushi
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Jun 06, 2011 12:14 am

Re: Custom error page returns 302 instead of 404

Post by yaksushi » Mon Jun 06, 2011 12:16 am

I'm having the same issue with my custom 404 page it also returns a 302 in google webmaster tools. anyone find the fix for this?

yaksushi
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Jun 06, 2011 12:14 am

Re: Custom error page returns 302 instead of 404

Post by yaksushi » Mon Jun 06, 2011 11:46 am

I've exhausted my Google skills..... I can't seem to find the solution.... Anyone have any ideas?

User avatar
leolam
Joomla! Master
Joomla! Master
Posts: 20652
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ Germany/ S'pore/Bogor/ North America
Contact:

Re: Custom error page returns 302 instead of 404

Post by leolam » Mon Jun 06, 2011 6:00 pm

@ Yaksushi:
You have been reported by me for sending me unsolicited support requests; Something I do not appreciate at all! http://forum.joomla.org/viewtopic.php?f=8&t=65 first dot reads:
DO NOT SEND SUPPORT REQUESTS VIA PM, unless expressly invited to do so. Using PM to actively solicit work is not allowed. Post, in accord with the rules in the correct forum. Abuse of the PM system in this way can lead to your membership being removed.
Leo
Joomla's #1 Professional Services Provider:
#Joomla Professional Support: https://gws-desk.com -
#Joomla Specialized Hosting Solutions: https://gws-host.com -

yaksushi
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Jun 06, 2011 12:14 am

Re: Custom error page returns 302 instead of 404

Post by yaksushi » Mon Jun 06, 2011 6:54 pm

leolam wrote:@ Yaksushi:
You have been reported by me for sending me unsolicited support requests; Something I do not appreciate at all!
Leo
Wow bro, relax..... I sent you a message regarding your post to this topic, nothing else. And it wasn't "Requests" it was a single PM.... Get off your high hoarse and chill out. Your Level 98 Dark Elf Mage will still be there waiting for you.

Again I apologize for interrupting your day with my extremely intrusive singular message. :-\

User avatar
reggaebkk
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 176
Joined: Mon Jul 14, 2008 1:39 pm

Re: Custom error page returns 302 instead of 404

Post by reggaebkk » Tue Jan 03, 2017 6:28 am

Hi, I would like to revive this topic that seemed to have been halted on some bad vibe.

I am having more or less the same problem but I am basing my observation on stats rather than logs and scripts:

I was having 130 404 and 25 302 errors per day in my stats, so I made a custom 404 page following the Joomla docs recommendations.

All seems to work fine but now I check my stats and I see that while I don't have 404 errors anymore, I am having nearly 200 302 errors per day.

Since 302 are "Moved temporarily (redirect)", I guess that it's normal, but I have 2 questions:

1/ Is there something I can do to avoid these redirects being seen as an error and a redirect?

2/ Does Google see the trick, does that have an impact on my website image towards Google algorithm?

User avatar
reggaebkk
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 176
Joined: Mon Jul 14, 2008 1:39 pm

Re: Custom error page returns 302 instead of 404

Post by reggaebkk » Fri Jan 06, 2017 6:26 am

Just checking: nobody knows the answer? Or did I just say something stupid that doesn't deserved to be replied to? Please enlighten me.

danielecr
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Apr 16, 2015 3:33 pm

Re: Custom error page returns 302 instead of 404

Post by danielecr » Fri Apr 28, 2017 3:32 pm

Hello,
I also noticed that the header/location trick:

Code: Select all

if (($this->error->getCode()) == '404') {
header('Location: /index.php?option=com_content&view=article&id=75');
exit;
}
generates 302 redirects and this is not good for seo!

After searching a lot, I decided to directly edit the error.php page without writing a new custom 404 page article and menu.

Take into account that in the error.php page you cannot include plugins, but you can include scripts and modules, for example:

Code: Select all

<?php $module = JModuleHelper::getModule('custom', 'name_of_custom_module');
echo JModuleHelper::renderModule($module); ?>
The above example includes the custom module "name_of_custom_module".

And so, this is valid for menus also.
By coding html and css I was able to 100% replicate the page I wanted for my custom 404 error page.

And, obviously, this returns a real 404 response!


Some info also here:
https://docs.joomla.org/Custom_error_pages


Locked

Return to “General Questions/New to Joomla! 1.5”