If you want to integrate the 'q' parameter within the rewrite use the below code for the controller
This will make the url search-for-something-in-my-shop.php
return
catalogsearch/result/?q=something
Just like a .htaccess reWriteRule
<?php
namespace Vendor\Module\Controller;
class Router implements \Magento\Framework\App\RouterInterface
{
private $actionFactory;
/**
* Response
*
* @var \Magento\Framework\App\ResponseInterface
*/
protected $_response;
/**
* Router constructor.
* @param \Magento\Framework\App\ActionFactory $actionFactory
* @param \Magento\Framework\App\ResponseInterface $response
*/
public function __construct(
\Magento\Framework\App\ActionFactory $actionFactory,
\Magento\Framework\App\ResponseInterface $response
)
{
$this->actionFactory = $actionFactory;
$this->_response = $response;
}
/**
* @param \Magento\Framework\App\RequestInterface $request
* @return \Magento\Framework\App\ActionInterface|null
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
$identifier = trim($request->getPathInfo(), '/');
if(strpos($identifier, '-in-my-shop.php') !== false && strpos($identifier, 'search-for-') !== false) {
$searchString = str_replace("replacement-","",$identifier);
$searchString = str_replace("-batteries.php","",$searchString);
$request->setModuleName('catalogsearch')->setControllerName('result')->setActionName('index')->setParam('q',$searchString );
} else {
//There is no match
return;
}
/*
* We have match and now we will forward action
*/
return $this->actionFactory->create(
'Magento\Framework\App\Action\Forward',
['request' => $request]
);
return null;
}
}