I have trouble with links in joomla 3.8. I have link like http://mysite.loc/my-category/my-subcategory/89 and this is correct link for material with id 89. But when i enter http://mysite.loc/my-category/my-subcategory/89asdasdasdasd Joomla show me this page, and repsonce 200/ok. How can i handle this and show 404 error for URL's like this ? SEF Is turned on
Joomla 3.8 404 error on incorrect links
400 Views Asked by Sergey Smekodub At
2
There are 2 best solutions below
0
On
I find solution its works for me. In class ContentRouterRulesLegacy find method parse, and where its call query to db to execute the article info put.
$query = $db->getQuery(true)
->select($db->quoteName(array('alias', 'catid')))
->from($db->quoteName('#__content'))
->where($db->quoteName('id') . ' = ' . (int) $id,'AND')
->where($db->quoteName('alias') . ' = ' . "'$alias'");
$db->setQuery($query);
$article = $db->loadObject();
if ($article)
{
if ($article->alias == $alias)
{
$vars['view'] = 'article';
$vars['catid'] = (int) $article->catid;
$vars['id'] = (int) $id;
return;
}
}
else
{
header('HTTP/1.0 404 Not Found');
JError::raiseError(404, 'JGLOBAL_RESOURCE_NOT_FOUND');
exit(404);
}
Yes - this is how Joomla behaves. When you have something like
yoursite.com/my-category/123-blablabla, Joomla will load the article having123as an ID. In fact, the article with ID123doesn't even have to be in themy-categorycategory. This is one of the weird things in Joomla.The solution to this problem is to remove the article ID from the URL as described here. Keep in mind 2 things though: 1) this is a core modification, and 2) the instructions on how to do so may be slightly different for 3.8.+.