CI 2.x->3.x Redirect? |
I'm upgrading from CI 2.x to CI 3.x. I have this line in my default controller for users who aren't logged in:
PHP Code: redirect('/auth/login/'); This used to redirect to: http://localhost/index.php/auth/login/ ...but now is redirecting to: http://localhost/localhost/index.php/auth/login/ Where's the right place for me to begin looking for the way to correct this?
In config.php make sure that $config['base_url'] is set. You used to be able to get away with not setting it. Not so with CI 3.x.
Update: After the redirect, in CodeIgniter.php, looking in $_SERVER[], I see:
Code: [REDIRECT URL] = "/localhost/index.php/auth/login/" That is as expected. But I also see: Code: [PHP_SELF] = "/index.php/localhost/index.php/auth/login/" Does that shed any light?
Update: Looks like it's happening in site_url($uri)... investigating...
I access my development site using 'localhost', e.g. 'localhost/auth/login'. I have $config['base_url'] set to 'localhost'. Is that correct?
Tracing through the redirect code, I get to this at the bottom of function redirect():
PHP Code: header('Location: '.$uri, TRUE, $code); $uri = "localhost/index.php/auth/login/" $code = 307 But, it appears to redirect to: http://localhost/localhost/index.php/auth/login/ Does this provide a clue?
Tracking it down!
redirect('/auth/login/'); ...is updated by function redirect() to: $uri = "localhost/index.php/auth/login/" ...which looks good. The redirect takes place and CodeIgniter restarts for the new URL. Then in CodeIgniter.php, line 402, the following line executes: if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php')) APPPATH.'controllers/'.$RTR->directory.$class.'.php' evaluates to : "/Applications/myApp/application/controllers/Localhost.php" ...even though localhost is not a controller. This results in a 404 error. It appears that on the call to: Code: public function set_class($class) ...in Router.php, $class has been set to localhost, based on the URL "localhost/index.php/auth/login/". This does not seem to be the expected behavior. What am I missing?
In application/config.config.php what is $config['base_url'] = ?????
It should probably be PHP Code: $config['base_url'] = 'http://localhost/';
That fixed it. I just had:
$config['base_url'] = 'localhost/'; Thank you very much! |
Welcome Guest, Not a member yet? Register Sign In |