Frontend
Search

Result Landing Page (SRLP) URL

6min

Change Default SRLP URL

The Search Result Landing Page (SRLP) URL in Magento (without any changes) is /catalogsearch/result. In v2.x/v3.x version of the Klevu module an extra SRLP route was added with a URL of /search. Having 2 routes is not ideal. In v4.x there is only one search route and by default, that route is the same as the Magento default, i.e. /catalogsearch/result.

If you are migrating from v2.x/v3.x maintaining the same route as previously implemented may be desirable. Alternatively, you may want something completely different, that choice is yours. This document shows you how you would make that change.

In v2.x/v3.x it was possible to switch between the 2 SRLP URLs to compare the search results from Klevu and native Magento. This can still be done by adding ?klevu_layout_preview=klevu or ?klevu_layout_preview=native to the SRLP URL.

Note all examples below use Module Vendor_Module. Update to match your module. How to create a module.

1. Create the Route

Create a new route so Magento directs the request to your module.

Vendor/Module/etc/frontend/routes.xml

  • The route id MUST be catalogsearch.
  • The route frontName is your new search URL, replace your-search-url with your desired URL.
  • <module MUST set before="Klevu_FrontendSearch" to replace config in the module Klevu_FrontendSearch. Also ensure your module.xml has a dependency on Klevu_FrontendSearch.

2. Define the Controller Name

Pass the controller name to the LandingUrlProvider. This handles the second part of the request url. Without this, the Klevu plugin will not provide the correct SRLP URL to Klevu when triggering the search.

Vendor/Module/etc/frontend/di.xml

  • controllerName is the directory containing the Action i.e. $this->request->getControllerName().
  • By Default controllerName is result. This directs requests to the controller Controller/Result/Index.php i.e. your.site/catalogsearch/result.
  • If using Index as the controllerName you can pass / as the controllerName argument. e.g. Controller/Index/Index.php i.e. your.site/search.

3. Create A Controller To Handle The Request

Vendor/Module/Controller/ControllerNameChangeMe/Index.php

  • Change ControllerNameChangeMe in the Controller path and namespace to match that set in LandingUrlProvider controllerName argument in etc/frontend/di.xml (see previous step).