redirect url helper redirect to localhost |
Hi,
When a call a redirect url helper function this function as following: redirect('controller/method'); redirect to http://localhost/index.php/controller/method If I set base_url variable on config file works correctly and redirect to http://myvirtualhost.com/index.php/controller/method but this not was necessary on codeigniter 2 and can be a problem because we must to define a base_url per environment. Greetings.
(05-08-2015, 01:53 AM)rtorralba Wrote: Hi, Did you create a route link in config/routes.php $route['controller/function'] = "controller/function"; $route['controller/function/(:any)'] = "controller/function/$1"; May not be necessary but just checking
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!
(05-08-2015, 01:53 AM)rtorralba Wrote: can be a problem because we must to define a base_url per environment. You can create config files based on the environment, so each one would have its own base_url. http://www.codeigniter.com/user_guide/li...vironments (05-12-2015, 10:42 AM)CroNiX Wrote:(05-08-2015, 01:53 AM)rtorralba Wrote: can be a problem because we must to define a base_url per environment. I know it, but it works on codeigniter 2 without definer base_url for two enviroments and, repeat entire config file just to this line? I can use enviromnet variable too, but I think is too much usually to have diferent domains for develop and production, then, in ci 3 almost all times we must duplicate this file. I think whould be more practical that if you don't define base_url it mantains the current, that would work at all environments. Greetings. (05-13-2015, 12:44 AM)rtorralba Wrote:(05-12-2015, 10:42 AM)CroNiX Wrote:(05-08-2015, 01:53 AM)rtorralba Wrote: can be a problem because we must to define a base_url per environment. Hi, I viewed that in ci3 has ENVIRONMENT constant defined in index file, in ci 2 I also defined, then, although I think is better maintain current domain, but it can be done the following: $config['base_url'] = ENVIRONMENT == 'development' ? 'domain.dev' : 'domain.com'; Greetings.
You also don't have to copy the whole config file. Just the values you want to override. CI will still load the default /config/config.php file, and then load /config/ENVIRONMENT/config.php. So you'd only need to change the base_url in /config/ENVIRONMENT/config.php and don't have to have everything else. That's explained in the docs I linked to.
(05-13-2015, 07:07 AM)CroNiX Wrote: You also don't have to copy the whole config file. Just the values you want to override. CI will still load the default /config/config.php file, and then load /config/ENVIRONMENT/config.php. So you'd only need to change the base_url in /config/ENVIRONMENT/config.php and don't have to have everything else. That's explained in the docs I linked to. Ah, ok, thanks, i suposed that new config file replace entire the other, just overwrite the variables defined on the new file
In most cases, redirect('controller/method') should still work in this manner without setting the base_url, though you should set the base_url anyway. If it doesn't work, it would imply that site_url('controller/method') is not working, either.
All of this implies that some combination of settings (base_url, enable_query_strings, url_suffix, and index_page seem to be the most likely candidates) causes site_url() to fail. Where does redirect('controller/method') attempt to send you when base_url is empty? (05-13-2015, 07:47 AM)mwhitney Wrote: In most cases, redirect('controller/method') should still work in this manner without setting the base_url, though you should set the base_url anyway. If it doesn't work, it would imply that site_url('controller/method') is not working, either. When base_url is not set redirect('controller/method') redirect to http://localhost/index.php/controller/method, the other projects in ci 2 redirect to the current domain (http://example.dev/index.php/controller/method). I think that something change in ci 3 because the documentation in config file has changed, now in ci 3 say that is recomended set this value. Greetings. (05-13-2015, 08:03 AM)rtorralba Wrote: When base_url is not set redirect('controller/method') redirect to http://localhost/index.php/controller/method, the other projects in ci 2 redirect to the current domain (http://example.dev/index.php/controller/method). The localhost value would seem to point to the else condition here: https://github.com/bcit-ci/CodeIgniter/b...ig.php#L72 Are you using 2.2 for your CI2 projects, or an earlier version? 2.2 and 3.0 use the same code for this particular section, and I can't really figure out where the localhost would come from, otherwise. The big difference between <=2.1 and >=2.2 on this line is the preg_match() validation, so, if the HTTP_HOST value fails the validation, it would revert to localhost. |
Welcome Guest, Not a member yet? Register Sign In |