Trailing Slash?

Hey everyone, so im making a page that loads in stats for users, and everything works until you look something up without a /.
For example,
http://localhost/forums/stats/user <-- Doesn't work
http://localhost/forums/stats/user/ <-- Works

So how would I go about adding a trailing slash for links that dont have one?
Heres my route :

PHP:
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $action = $router->resolveActionWithStringParam($routePath, $request, 'username');
        $action = $router->resolveActionAsPageNumber($action, $request);
       
        $actions = explode('/', $action);
        switch ($actions[0])
        {
            case 'search':    $controller = 'Search';        break;
            default:            $controller = '';
        }
       
        return $router->getRouteMatch('bdStats_ControllerPublic_Stats', $controller, $action, 'stats');
    }
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
            return XenForo_Link::buildBasicLinkWithStringParam($outputPrefix, $action, $extension, $data, 'username');
    }
 
Any links created with the XF link builder will automatically have the trailing slash. Generally it won't work if you remove the slash but, really, who's going to do that?

I'd say it's probably not worth working around, but in case you do want to, there may be some guidance in the following bug report:

https://xenforo.com/community/threads/potential-bug-with-xenforo_router-getsubcomponentaction.66322/

That's not the exact solution but it may help.
Thanks for the quick reply man! Ive tried using the code like this, and cant seem to get it to work, what does the "2" in "$routePath, 2" represent?
PHP:
        $parts = explode('/', $routePath, 2);
        if (isset($parts[0]))
        {
            if ($parts[0] == 'stats')
            {
                if (utf8_substr($parts[1], -1) != '/')
                {
                    $parts[1] .= '/';
                }

                $routePath = implode('/', $parts);
            }
        }
        $action = $router->resolveActionWithStringParam($routePath, $request, 'username');
        $action = $router->resolveActionAsPageNumber($action, $request);
        return $router->getRouteMatch('bdStats_ControllerPublic_Stats', $action, $routePath, 'stats');
 
It sets a limit on explode(). Meaning $parts[0] will contain everything before the first "/" and $parts[1] will contain the rest.
http://php.net/manual/en/function.explode.php
Does the way I have it in my route look correct ? I apologize for my lack of understanding, http://localhost/forums/stats/user/ works and http://localhost/forums/stats/user doesn't, Im trying to force a trailing slash onto it, just cant seem to get it to work, again sorry for my lack of understanding, and thank you for your help an time.
 
i know how removed you need just create a page rules on cloudflare i have fix ! but if am not running on cloudflare this issues rest!! possible dont know any 1 how fix on .htaccess?
 
Back
Top Bottom