Hello everyone,
just to give an update to whoever has the same problem, I succeeded with my redirection.
I found that the class
\vB5_Frontend_Routing (file: vb5/includes/vb5/frontend/routing.php) manages the requests and tries to find out what page should be displayed to the user.
Every page request will fall into
\vB5_Frontend_Routing::setRoutes, which will try to create the route to the requested path. And this is the piece of the code:
PHP Code:
try {
$message = ''; // Start with no error.
$route = Api_InterfaceAbstract::instance()->callApi('route', 'getRoute', array('pathInfo' => $path, 'queryString' => $_SERVER['QUERY_STRING']));
}
My problem was: once I migrated from an existing forum to vBulletin, I had to create redirection for all my existent threads and forums. However, once I have hundreds of thousands of links, it didn't seem smart adding all of them to htacess.
So, once I have a custom routine to create vBulletin path from a legacy path, this is my result:
PHP Code:
try {
$message = ''; // Start with no error.
$route = Api_InterfaceAbstract::instance()->callApi('route', 'getRoute', array('pathInfo' => $path, 'queryString' => $_SERVER['QUERY_STRING']));
// begin: my custom redirection
if (isset($route) && $route == false) {
$newPath = MyClass::getVBPathFromLegacyPath($path); # this custom function returns string or false
if ($vbPath !== false) {
$route = Api_InterfaceAbstract::instance()->callApi('route', 'getRoute', array('pathInfo' => $path, 'queryString' => $_SERVER['QUERY_STRING']));
$route['redirect'] = $newPath; # this is important, so vBulletin will create a 301 redirection
}
}
// end: my custom redirection
}
As we can see, the code is executed
only in the case vBulletin is
not able to create a
route. And it only creates a route in the case a
newPath (which is a vBulletin path, created using vBulletin API) is successfully created.
To me, it seems safe. And I hope the
redirect parameter set "by hand" doesn't break things at some point.
So far, in a test environment, everything looks fine.