0 I want to remove Plus mark in end of the URL String How to do this in Magento 2.3 community Version


My intuition tells me that the query text includes basically spaces and you would like to remove the spaces between the words in the query text.

You could create an observer on the controller_action_predispatch_catalogsearch_result_index event:

in your module, in etc/frontend/events.xml file, add:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch_catalogsearch_result_index">
        <observer name="change_query_text" instance="Vendor\Module\Observer\ChangeQueryText"/>

in your observer class Vendor\Module\Observer\ChangeQueryText.php, you can change this:


namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event\Observer;

 * Class ChangeQueryText
 * @package Vendor\Module\Observer
class ChangeQueryText implements ObserverInterface
    private $request;

     * @param RequestInterface $request
    public function __construct(
        RequestInterface $request
    ) {
        $this->request = $request;

     * @param Observer $observer
    public function execute(Observer $observer)
        $queryString = trim($this->request->getQuery('q'));
        $newQuery = preg_replace('/\s+/', '', $queryString);
        $this->request->setParam('q', $newQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.