Hi @soho_rize,
One way to perform such redirect is adding a plugin for \Magento\Cms\Controller\Noroute\Index. Configuration for etc/di.xml for this purpose:
<type name="Magento\Cms\Controller\Noroute\Index">
<plugin name="noroute_redirect"
type="YourVendor\YourModule\Plugin\Noroute" />
</type>
And the plugin will look like:
<?php
namespace YourModule\YourVendor\Plugin;
class Noroute
{
private $redirectFactory;
public function __construct(\Magento\Framework\Controller\Result\RedirectFactory $redirectFactory)
{
$this->redirectFactory = $redirectFactory;
}
public function aroundExecute(
\Magento\Cms\Controller\Noroute\Index $index,
\Closure $proceed
) {
return $this->redirectFactory->create()
->setPath('404notfound');
}
}
You should also create a CMS Page specifying the 404notfound url-key to handle request to this url.
Unfortunately, Magento 2 framework does not allow to save pages with number-only url key.