Adding suffix to parseRequest() URLs

I’m extending the UrlRuleInterface class for custom URL rules

I’m trying to redirect the url to add a suffix / if the url doesn’t have it.

public function parseRequest($manager, $request)
    {
       
        $matches = explode('/', $request->getPathInfo());
  
        //if last array is empty, unset it!
        if (empty(end($matches))) { 
            unset($matches[count($matches) - 1]); 
        } else {
            //add code to redirect to controller and action here
            
        }

How do i get the controller and action of the URL so i can redirect my custom URLs to add the /

The forcing suffix works fine on other URLs, but not my custom URLs.

in my main.php i have this

'urlManager' => [
           'class' => 'yii\web\UrlManager',
           'enablePrettyUrl' => true, 
           'showScriptName' => false,
           'enableStrictParsing' => true,
           'suffix' => '/', 
           'normalizer' => [
                'class' => 'yii\web\UrlNormalizer',
            ],
           'rules' => require ('urls.php'),
        ],

Controller and action are determined after URL match, not before it.

See yii2-cookbook/handling-trailing-slash-in-urls.md at master · samdark/yii2-cookbook · GitHub