在magento2中通过frontName进行路由,如{frontName} / [params1] / [paramsX] ... [?queryString]

Magento2 processing requests with the structure like:

{frontName}/{controller}/{action}

but i need to process some requests with the structure like

{frontName}/[params1]/[paramsX]...[?queryString]

what's the best way to solve it? Event linstener for controller_front_send_response_before? Interceptor for Magento\UrlRewrite\Controller\Route? or any other ... thanks very much

maybe .htaccess rewrite?

thank for @RobbieAverill's comment. the link is useful.

i created di.xml in app/code/MyVendor/MyModule/etc/frontend with:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

<type name="Magento\Framework\App\RouterList">
    <arguments>
        <argument name="routerList" xsi:type="array">
            <item name="app_api_router" xsi:type="array">
                <item name="class" xsi:type="string">MyVendor\MyModule\Controller\Router</item>
                <item name="disable" xsi:type="boolean">false</item>
                <item name="sortOrder" xsi:type="string">10</item>
            </item>
        </argument>
    </arguments>
</type>

</config>

and created Router.php in app/code/MyVendor/MyModule/Controller/Router.php

<?php
namespace MyVendor\AppApi\Controller;

class Router implements \Magento\Framework\App\RouterInterface
{
    public function match(\Magento\Framework\App\RequestInterface $request)
    {
        $identifier = trim($request->getPathInfo(), '/');
        if(strpos($identifier, 'routes.xml frontName') === 0) {
            // MY LOGIC CODE HERE
        }
    }
}