Welcome Guest, Not a member yet? Register   Sign In
$routes->addRedirect with regex?
#2

The addRedirect() method does not support replacement.

You can use this hack
PHP Code:
$routes->any('subdir/([a-z\-]+)/([a-z\-]+)-(\d{2}-\d{4}\.\d{2})\.html', function(){
    $router Services::router();
    $request Services::request();
    $path preg_replace(
        '#^' $router->getMatchedRoute()[0] . '$#u',
        $router->getMatchedRouteOptions()['redirect'],
        $request->uri->getPath()
    );
    throw new RedirectException($path);
}, [
'redirect' => 'subdir/$1/$2-$3']); 

Or create your own class that extends the Router class and implement a replacement in it.
Or post a new issue on github or PR with fixes or comment in the documentation about the inability to use regex.
Reply


Messages In This Thread
$routes->addRedirect with regex? - by sneakyimp - 02-10-2021, 05:31 PM
RE: $routes->addRedirect with regex? - by iRedds - 02-11-2021, 03:37 AM
RE: $routes->addRedirect with regex? - by iRedds - 02-11-2021, 11:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB