CI 2.x->3.x Redirect? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9) +--- Thread: CI 2.x->3.x Redirect? (/showthread.php?tid=66610) |
CI 2.x->3.x Redirect? - VikRubenfeld - 11-11-2016 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? RE: CI 2.x->3.x Redirect? - dave friend - 11-11-2016 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. RE: CI 2.x->3.x Redirect? - VikRubenfeld - 11-11-2016 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? RE: CI 2.x->3.x Redirect? - VikRubenfeld - 11-11-2016 Update: Looks like it's happening in site_url($uri)... investigating... RE: CI 2.x->3.x Redirect? - VikRubenfeld - 11-11-2016 (11-11-2016, 04:01 PM)dave friend Wrote: 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. I didn't see this before-- checking now... RE: CI 2.x->3.x Redirect? - VikRubenfeld - 11-11-2016 I access my development site using 'localhost', e.g. 'localhost/auth/login'. I have $config['base_url'] set to 'localhost'. Is that correct? RE: CI 2.x->3.x Redirect? - VikRubenfeld - 11-11-2016 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? RE: CI 2.x->3.x Redirect? - VikRubenfeld - 11-11-2016 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? RE: CI 2.x->3.x Redirect? - dave friend - 11-11-2016 In application/config.config.php what is $config['base_url'] = ????? It should probably be PHP Code: $config['base_url'] = 'http://localhost/'; RE: CI 2.x->3.x Redirect? - VikRubenfeld - 11-12-2016 That fixed it. I just had: $config['base_url'] = 'localhost/'; Thank you very much! |