PDA

View Full Version : Custom Error Page with correct HTTP response


marcmerz
11-08-2004, 06:13 PM
When i try to reach a page inside CMPS that does not exist, i get returned to the main page. Not too bad. But: The HTTP status code returned is 200. Usually you would not care but the problem is the bots. If -for some reason- such a non existing page gets into a search engine index, it will stay there forever and would just be a copy of your CMPS main page.

Is it possible to return the correct status code in case a CMPS page does not exist?

I would love to see this functionality because when the correct status code is sent, it would be easy to use something like:
ErrorDocument 404 /index.php?page=error404in a .htaccess file and (at the same time) set up a error404 page inside CMPS to display a custom error page.

Right now, because a 200 is returned even on non existing pages, you can not do something like this.

I would be quite happy to dig around with the CMPS php code if i got a hint where to look at.

marcmerz
11-09-2004, 03:38 PM
I found a solution. If you want to use my solution MAKE A BACKUP FIRST. I tested it and did not find a problem but i do not guarantee anything.

1. Create a page called error404 and a template called adv_portal_error404.

2.
In /includes/vba_cmps_include_top.php find:
if (!$pages['pageid'])
{
$pages = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "adv_pages WHERE name = 'home'");
}
and replace it with:
if (!$pages['pageid'])
{
$pages = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "adv_pages WHERE name = 'error404'");
header("HTTP/1.0 404 Not Found");
}

When someone requests a page that does not exit, he gets your error404 page with the description you wrote in the adv_portal_error404 template and a correct http status code 404 is sent from the server.

For errors like 410:
Simply create a page called error410 and a corresponding template and in your .htaccess you put:ErrorDocument 410 /portal.php?page=error410

@Brian:
If you approve this small hack, maybe you can copy/move this thread to a more appropriate place.