Yes, you can achieve the desired behavior of handling 404 errors and using Joomla's redirect table in combination with VirtueMart.
You can implement this functionality by creating a custom plugin or using an existing plugin that allows you to customize the redirection process.
Here are some steps..
- Create a custom Joomla plugin that triggers on the onAfterRoute event. This event occurs after Joomla has determined which component should handle the current request.
- In the plugin, check if the current request resulted in a 404 error. You can do this by examining the HTTP response code (https://redirectchecker.com/).
- If a 404 error is detected, query the Joomla redirect table to check if there is an entry for the requested URL.
You can use Joomla's database API to perform this query. - If there is a matching entry in the Joomla redirect table, redirect the request to the new URL specified in the redirect entry.
If there is no entry, redirect the request to the VirtueMart shop's start page.
Here is an example code to give you an idea of how the plugin could be implemented...
use Joomla\CMS\Plugin\CMSPlugin;
class plgSystemCustomRedirect extends CMSPlugin
{
public function onAfterRoute()
{
$app = JFactory::getApplication();
// Check if the current request resulted in a 404 error
if ($app->isClientError(404)) {
// Get the requested URL
$requestedUrl = JUri::current();
// Query the Joomla redirect table for a matching entry
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('new_url')
->from('#__redirect_links')
->where('old_url = ' . $db->quote($requestedUrl));
$db->setQuery($query);
$newUrl = $db->loadResult();
// If there is a matching entry, redirect to the new URL
if ($newUrl) {
$app->redirect($newUrl);
} else {
// If no entry is found, redirect to VirtueMart shop's start page
$app->redirect('index.php?option=com_virtuemart');
}
}
}
}
This is just a simplified example, and you may need to adapt the code to fit your specific Joomla and VirtueMart versions.