3

I have a product view which shows a product if a it exists at a link like:

www.example.com/products/product-name

If the product does not exist, an error page is displayed instead of the server issuing a redirect to an error like /404

If a product is created after Googlebot views it as an error, Google lists the page as an error page because it was viewed before as an error. Is it therefore better to redirect the page to a 404? Or will Google eventually update and stop viewing it as an error?

My current code is like this (not exactly but it works this way)

Controllers/Router/Map::('/products/[*:name]', function($productName) {
    $p = Controllers/Products/Loader::getProductByName(implode(' ', explode('-', $productName));
    require_once(_DIR_ . ($p->isProduct() ? 'views/product.php' : 'views/error.php'));
});

Should I be requiring the error view or redirecting the server to the 404 link?

7
  • Do you return a status code of 404 with your error view?
    – BobDalgleish
    Commented Oct 25, 2016 at 14:09
  • No it just requires the file and displays it, so if i was to send the link the meta would be the error meta for that invalid product. Rather than it it becoming /404 @BobDalgleish
    – Kyle Thomas
    Commented Oct 25, 2016 at 14:10
  • The page seems to become a live page because i havent redirected it away, how can i do this?
    – Kyle Thomas
    Commented Oct 25, 2016 at 14:11
  • I believe that search engines won't cache error pages if the status is 404. A normal status of 200, etc, will cause everybody to assume that the result was intentional, i.e., good. As for how to set the status code on your page, that is done in your web framework.
    – BobDalgleish
    Commented Oct 25, 2016 at 14:13
  • The SEO is fine, i mean, this code effects the page SEO, how can i redirect the page away to the 404 error file rather than requiring it? @amon is Header('Location: ...'); my best bet?
    – Kyle Thomas
    Commented Oct 25, 2016 at 14:14

1 Answer 1

1

To resolve this issue, either change your code so that:

(a) products which don't have an associated product page are not given a hyperlink and therefore not clickable so that users and search engines don't end up on page-not-found error pages; or

(b) to prevent search engines from indexing your error pages, ensure that your 404 error page has an HTTP header set as follows before any HTML content is output:

<?php
header('HTTP/1.0 404 Not Found');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.