I matured the code a bit further and came up with the following
in components/com_sef/joomsef.php line 1203
replace this
if( $params->get('varFilterFail', '0') == '1' ) {
// We need to test the URL using variable filter
// in order to stop its further processing in case it fails
$failedVars = array();
if( !JoomSEF::_varFilterTest($uri, $failedVars) )
{
die($uri->toString() . '<br />' . JText::_('URL did not pass the variable filter test.'));
}
}
for this
if( $params->get('varFilterFail', '0') == '1' ) {
// We need to test the URL using variable filter
// in order to stop its further processing in case it fails
$failedVars = array();
if( !JoomSEF::_varFilterTest($uri, $failedVars) )
{
// redirect to the error page
if ($sefConfig->showMessageOn404) {
$mosmsg = 'FILE NOT FOUND: '.$route;
$mainframe->enqueueMessage($mosmsg);
}
else $mosmsg = '';
$link = '';
if ($sefConfig->page404 == '0') {
$db = JFactory::getDBO();
$sql = 'SELECT `id` FROM `#__content` WHERE `title`= "404"';
$db->setQuery($sql);
if (($id = $db->loadResult()))
$link = 'index.php?option=com_content&view=article&id=' . (int) $id;
}
elseif ($sefConfig->page404 == '9999999') {
$menu =& JSite::getMenu(true);
$item = $menu->getDefault();
$link = $item->link;
}
else {
$id = $sefConfig->page404;
$link = 'index.php?option=com_content&view=article&id=' . (int) $id;
}
// If custom Itemid set, use it
if ($sefConfig->use404itemid) {
$link .= '&Itemid=' . $sefConfig->itemid404;
}
//JoomSEF::_sendHeader('HTTP/1.0 506 Proxy Authentication Required'); //so it does not make sense mixed 506 with 407 error codes
header("HTTP/1.0 404 Not Found");
if ($link)
{
// Try to find the non-SEF URL in the database - don't create new!
$oldDisable = $sefConfig->disableNewSEF;
$sefConfig->disableNewSEF = true;
$sef = JRoute::_($link);
// Restore the configuration
$sefConfig->disableNewSEF = $oldDisable;
$f = $l = '';
if( !headers_sent($f, $l) )
{
$mainframe =& JFactory::getApplication();
$mainframe->redirect($sef, $mosmsg, 'error');
exit();
} else {
JoomSEF::_headers_sent_error($f, $l, __FILE__, __LINE__);
}
}
die($uri->toString() . '<br />' . JText::_('URL did not pass the variable filter test.'));
}
}
this will consider all the scenarios for the 404 error page:
- pointing to an existing article
- pointing to homepage
- default 404 page
I was not able to change the response headers to something like 404 or 500 but I think it would be easy for the joomSEF team to do that bit.
As I said earlier I think this could be a nice thing to have as it looks a lot better than a
die($uri->toString() . '<br />' . JText::_('URL did not pass the variable filter test.'));
But I would like to ear other opinions,
specially from the joomsef development team.
Regards