0
votes

I want to create location pages in my codeigniter site. So I have one contrller named locations and index method. So all the requests http://mysite.com/location_name should be landed to http://mysite.com/index.php/locations/index. And all other should work as it is like http://mysite.com/login should be landed to http://mysite.com/index.php/home/login. Contact us http://mysite.com/contact-us should be landed to http://mysite.com/index.php/home/contact.

I tried to achieve this by writing following line route rule (route.php):

$route['(:any)'] = 'locations';  //location name can be anything around the world

So locations are working fine, but http://mysite.com/login and http://mysite.com/contact-us are not working, they redirecting continuously in infinite loop.

Please suggest the solution. Thank.

1
As i remember the routes are by order of appearence, make sure u set the logic for login and contact-us before the (:any) - eric.itzhak
@eric.itzhak, thanks. But I have already tried with the order. I have written the rules for home, login and contact us first. And lastly for the any. Still facing the issue. - user987346

1 Answers

0
votes

The routes are applied from top to bottom, so you need to have your more specific rules listed first, then your more generic rules last:

$route['login'] = 'home/login';
$route['contact-us'] = 'home/contact';
$route['(:any)'] = 'location/index';

I see that you mentioned you've tried changing the order of rules in your route file. So If you have done this and it's not working - you have something else going on.

I would check these things:

  • .htaccess file (if you're using it)
  • controllers that are causing the infinite loop (any redirections in there, _remap method, etc. )