Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
470 views
in Plugins by

I am developing a shortlink plugin, that takes the userid and redirects to the userprofile.

Instead of: domain.com/u?123 (where I can easily catch the request by a page plugin and read the userid)

I would like a slash: domain.com/u/123

However, having a slash there, the page plugin cannot catch the "u" request anymore.

How to proceed here, best practice?

The standard way does not work here:

        function match_request($request)
        {
            if($request=='u')
            {
                return true;
            }
            return false;
        }

Q2A version: 1.7.4

2 Answers

0 votes
by
edited by
Okay, I think I found the solution:

            if(strpos($request,'u/') !== false)
            {
                return true;
            }

Better solution:

        function match_request($request)
        {
            // do we have 'u/' in the request
            if(strpos($request,'u/') !== false)
            {
                $urlparts = explode('/', $request);
                // potential number
                if(!empty($urlparts[1]) && is_numeric($urlparts[1]))
                {
                    return true;
                }
            }
            return false;
        }
0 votes
by
edited by

If the pattern of your url is stable, this will also work for you

$req = $request; // supply url however you want!!!
$req = basename(dirname($req)); //no need for basename if $request is standard qa ->request
if($req === "u"){
   //do stuff here
}
...