Welcome Guest, Not a member yet? Register   Sign In
Setting redirection in Config/Routes.php seems to be broken
#1

(This post was last modified: 04-23-2020, 11:34 AM by jreklund.)

Suppose I have these route definitions in Config/Routes.php:

PHP Code:
$routes->setAutoRoute(true);

/**
* --------------------------------------------------------------------
* Route Definitions
* --------------------------------------------------------------------
*/

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/''Home::index');

$routes->addRedirect('OldStuff/PHP/API/Synchronization.php',        'Apps/NewStuff/synchronize'); 

The old stuff does not exist anymore (none of it) but is coming from an old implementation of the website. Now, if somebody is entering in the browser

Code:
http://www.mysite.com/OldStuff/PHP/API/Synchronization.php

this leads to a PHP error when throwing an exception in CodeIgniter. So, two errors at once!

Reason:

Router::checkRoutes is checking if the uri (OldStuff/PHP/API/Synchronization.php) can be found in the existing routes. This is obviously the case because the regular expression

PHP Code:
preg_match('#^' $key '$#'$uri$matches
 is true. And this is also the purpose.
If this is true the next statement checks if it is a redirection. Also this is true. Then, a RedirectException is thrown. Why is the exception thrown at all?
Unfortunately, the RedirectException is also called with the wrong parameters and therefore a PHP error occurs.

PHP Code:
throw new RedirectException(key($val), $this->collection->getRedirectCode($key)); 
$val is a simple value and not an array!  Sad

Anyway, the problem is: how do I do redirections in Config/Routes.php if not as shown? Huh
Reply




Theme © iAndrew 2016 - Forum software by © MyBB