Replace "Record not found!" with custom 404 Page not Found

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 28, 2015   (RSS)

By andybarn - April 27, 2015

Hi

I have a property website with the Permalinks plugin installed (I do not think this is relevant but thought it worth mentioning)

Some of my old listings are still indexed by Google, but the property in question has since been deleted. However when someone clicks on the link Google has -  http://www.comparedirect.eu/property/listingDetail.php?DO1615338-25479   they get a "Record not found!" error code.

My SEO person has said it would be better to handle this differently and asked could this not show a "404 page not found" error page instead (I have a custom 404 page setup and this works when going to a page not recognised but not when clicking the link from Google)

Thanks for your help.

Kind regards

Andy

By Damon - April 27, 2015

Hi Andy,

In your listingDetail.php template, replace the "Record not found!" code with a redirect to your 404 page.

Find this code:

if (!$newsRecord) { dieWith404("Record not found!"); } // show error message if no record found

Replace with this code:

if (!$newsRecord) { header('Location: http://www.comparedirect.eu/404-compare-direct.php'); } // redirect to 404 page


Hopefully this is what you were after!

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/