You are here:  » 404 page


404 page

Submitted by henk on Sat, 2012-12-29 22:32 in

Hi David,

Is it possible to get an 404 page for not found products, google webmaster gives me errors:

{link saved}

Thx
Henk

Submitted by support on Sun, 2012-12-30 10:15

Hi Henk,

I'm looking into this for version 2 as for global compatibility it must be implemented before any HTML content has been generated; however, if your PHP / WordPress set-up is configured to buffer content generation (for example if using gzipped pages which is in itself good for SEO) then you will be able to insert the 404 header at the point at which it can be identified that the product no longer exists. Look for the following code at line 288 of pto_product.php:

  return "";

...and REPLACE with:

  header("HTTP/1.0 404 Not Found");
  return "<p>Sorry, this product is no longer available.</p>";

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Sun, 2012-12-30 10:53

Hi David,

I've this error now:

Warning: Cannot modify header information - headers already sent by (output started at /public_html/wp-content/plugins/pto/pto_product.php on line 321

Thx
Henk

Submitted by support on Sun, 2012-12-30 12:10

Hi Henk,

That does indicate that your output is not buffered so without buffering a 404 header cannot be sent at that point. You should be able to turn on output buffering by adding the following code the end of your wp-config.php file, just before the closing PHP tag:

  ob_start();

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Sun, 2012-12-30 13:22

Great Thx.

Henk

Submitted by henk on Tue, 2013-01-29 08:41

Hi David,

Is it possible to have product on this page? Like related products?

Thx
Henk

Submitted by support on Tue, 2013-01-29 09:07

Hello Henk,

Yes, you could do this! In pto_product.php, where you made the above replacement:

  header("HTTP/1.0 404 Not Found");
  return "<p>Sorry, this product is no longer available.</p>";

...instead, have a go with something like this:

  header("HTTP/1.0 404 Not Found");
  $html = "";
  $html .= "<p>Sorry, this product is no longer available.</p>";
  $html .= pto_product_related((object)array("name"=>$pto_product));
  return $html;

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2013-01-29 09:43

Hi David,

Works great.

It's very strange that i got more and more 404 notifications but the products are available, is there a way to test it?

Henk

Submitted by support on Tue, 2013-01-29 09:49

Hello Henk,

It's most likely that the product name has changed, even just by 1 character would be enough for the old product URL to go 404 so that might be what you're seeing, but if you find a product that is definitely in the database but returning 404 for what should be its product page URL if you could let me know the product name and corresponding product page URL that is returning 404 I'll check it out...(I'll remove links before publishing your reply)

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2013-01-29 10:05

Hi david,

xml:

{code saved}

Not found product:

{link saved}

Maybee the url rewrite? or problems with the cheapest product name.

This product for sure its rewrite the ":"

{link saved}

Next set: jurk en legging

Thx
Henk

Submitted by support on Tue, 2013-01-29 11:01

Hello Henk,

Each of those links seemed to return a working product page, maybe i've mis-understood?

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2013-01-29 11:17

Hi David,

Yes, but in google webmaster it's a 404 page not found.
Maybe it's because:

product a: nike 123 € 100,-

other merchant in xml feed

product a: nike 123 red € 120,-

the last product gives back a 404 page but it's in the xml feed.

And i think google will give the first also a 404 not found later.
Hope you understand it :)
Thx
Henk

Submitted by support on Tue, 2013-01-29 12:09

Thanks Henk - I'll follow up by email...

Cheers,
David.
--
PriceTapestry.com

Submitted by koen on Tue, 2014-01-07 16:12

Hello David,

Sorry to kick this topic again, but in my installation the 404 is not working properly. It gives an empty page with only related products. I can't find any code in pto_product.php :(

Can you give me an hint on how to get it like a 404 (I've got an 404-to-start plugin installed to redirect 404's to the homepage that I want to use....)....

Cheers and thanks a lot!
Koen

Submitted by support on Tue, 2014-01-07 16:25

Hello Koen,

For the latest distribution look for the following code at line 184 of pto.php:

  pto_product_query();

...and REPLACE with:

  pto_product_query();
  global $pto_productResults;
  if (!count())
  {
    header("HTTP/1.0 404 Not Found");
  }

The above code executes before page generation so the appropriate header can be inserted into the output buffer. For a pure "404" you could follow the header() line with:

  exit();

...but without doing so, page should return 404 with related products showing as currently which should help the user fine alternative or maybe recently renamed versions of the product they were looking for...

Cheers,
David.
--
PriceTapestry.com

Submitted by koen on Wed, 2014-01-08 19:22

Thanks David.

It doesn't seem to be so easy...
The code I've placed is:

pto_product_query();
  global $pto_productResults;
  if (!count())
  {
    header("HTTP/1.0 404 Not Found");
  }

The result on a normal product page is:
Warning: count() expects at least 1 parameter, 0 given in /blabla/pto/pto.php on line 188
Warning: Cannot modify header information - headers already sent by (output started at /blabla/pto/pto.php:188) in /blabla/pto/pto.php on line 190

Can you help me find the problem?
Thanks!
Koen

Submitted by support on Wed, 2014-01-08 19:26

Sorry Koen - the replacement should be:

  pto_product_query();
  global $pto_productResults;
  if (!count($pto_productResults))
  {
    header("HTTP/1.0 404 Not Found");
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by koen on Thu, 2014-01-09 15:18

Hi David,

Sorry to bother you again on this one, but I can't get the code working :(
I've implemented your new code, but the non-existing page stays the same...
When I add the exit() the page remains totally empty....

Any idea?
Cheers,
Koen

Submitted by support on Thu, 2014-01-09 16:24

Hello Koen,

The fact that adding exit() leaves an empty page means that the code is being executed as expected. Please could you let me know

1) An example old product page that should be 404

2) An example of another "invalid" URL showing your actual 404 page that you would like to be displayed instead

(I'll remove the links before publishing your reply...)

Thanks!
David.
--
PriceTapestry.com

Submitted by koen on Thu, 2014-01-09 20:00

Hi David,

1. This one should be 404
{link saved}

2. This is a "classic" Wordpress 404 on my test site:
{link saved}

I'm using the 404-to-start WP-plugin on my production site, so then the 404 will be forwarded to my homepage. On my test site this plugin is disabled, giving me the possibility to create "real" 404's first.

Thanks!
Koen

Submitted by support on Fri, 2014-01-10 15:07

Hi Koen,

If you're happy for the invalid product pages to forward to your home page that can be done easily - where you removed exit(); from the above code, re-instate as:

  header("Location: /");
  exit();

Cheers,
David.
--
PriceTapestry.com