Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can you explain these two lines of code in applications/config/routes.php file in the CodeIgniter framework?

$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
share|improve this question
up vote 7 down vote accepted

The following information is taken from the CodeIgniter-Documentation under

Routing rules are defined in your application/config/routes.php file. In it you'll see an array called $route that permits you to specify your own routing criteria. Routes can either be specified using wildcards or Regular Expressions

So your first line of code would redirect any call to your domain, when the URI contains no data to the view-Method in the pages-class like that: would redirect to

The second line would redirect any call to the pages-class/view-method and pass the original URI as parameter like that: would redirect to

So, basically you're setting up a Front Controller with these two lines. Hope that helps.


In CodeIgniter, each URL can be splitted into class, method and data as stated here. Example: Normally, calling the URL http:/ would call the method 1 in the class article. Your second line of code would redirect this call to and therefor call the method view in the class pages passing the arguments "articles" and "1" as data.

I would like to encourage you to read through the excellent CI-Documentation to fully understand those principles.

share|improve this answer
can you please rephrase/elaborate part two(the second line)? – Kumar Mar 30 '12 at 9:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.