Uniform Resource Identifier or URI consists of a string of character used to name a resource on the Internet. The name of a resource on the Internet should be naming conventional so that Search Engine like google , yahoo, ask etc. can easily find out. And it can be possible if we arrange the URI perfectly following some rules of URI Routing. In CodeIgniter the segments in a URI normally follow a pattern like this -
www.mysite.com/myclass/myfunction/myparam
Suppose that we have a URL like below -
http://localhost/TestingServer/home/chidc/mid/4/sid/11/chid/12
where “http://localhost/TestingServer/” is our BASE URL and others are segments. If we describe the above URI following the CodeIgniter pattern -
http://localhost/TestingServer/home(myclass)/chidc(myfunction)/mid(paramname1) /4(paramvalue1)/sid(paramname2)/11(paramvalue2)/chid(paramname3)/12(paramvalue3)
Now we will apply our own routing rules to the above URL.
In CodeIgniter routing rules are defined in application/config/routes.php file.
// routes.php <?php if ( ! defined(’BASEPATH’)) exit(’No direct script access allowed’); /* | ————————————————————————- | URI ROUTING | ————————————————————————- | This file lets you re-map URI requests to specific controller functions. | | Typically there is a one-to-one relationship between a URL string | and its corresponding controller class/method. The segments in a | URL normally follow this pattern: | | example.com/class/method/id/ | | In some instances, however, you may want to remap this relationship | so that a different class/function is called than the one | corresponding to the URL. | | Please see the user guide for complete details: | | http://codeigniter.com/user_guide/general/routing.html | | ————————————————————————- | RESERVED ROUTES | ————————————————————————- | | There are two reserved routes: | | $route['default_controller'] = ‘welcome’; | | This route indicates which controller class should be loaded if the | URI contains no data. In the above example, the “welcome” class | would be loaded. | | $route['scaffolding_trigger'] = ’scaffolding’; | | This route lets you set a “secret” word that will trigger the | scaffolding feature for added security. Note: Scaffolding must be | enabled in the controller in which you intend to use it. The reserved | routes must come before any wildcard or regular expression routes. | */ $route['default_controller'] = “home”; $route['scaffolding_trigger'] = “”; /* End of file routes.php */ /* Location: ./system/application/config/routes.php */ ?>
Here $route is an array by which we can specify our own routing rules. Now we are going to specify our own routing rules below -
$route['childmenu/([0-9]+)/([0-9]+)/([0-9]+)’] = “home/chidc/mid/$1/sid/$2/chid/$3″;
Here segments childmenu and regular expressions will be remapped to the ‘home’ class , ‘chidc’ function and three params value ‘mid’, ’sid’, ‘chid’.
By adding above code to routes.php file -
// modified routes.php <?php if ( ! defined(’BASEPATH’)) exit(’No direct script access allowed’); /* | ————————————————————————- | URI ROUTING | ————————————————————————- | This file lets you re-map URI requests to specific controller functions. | | Typically there is a one-to-one relationship between a URL string | and its corresponding controller class/method. The segments in a | URL normally follow this pattern: | | example.com/class/method/id/ | | In some instances, however, you may want to remap this relationship | so that a different class/function is called than the one | corresponding to the URL. | | Please see the user guide for complete details: | | http://codeigniter.com/user_guide/general/routing.html | | ————————————————————————- | RESERVED ROUTES | ————————————————————————- | | There are two reserved routes: | | $route['default_controller'] = ‘welcome’; | | This route indicates which controller class should be loaded if the | URI contains no data. In the above example, the “welcome” class | would be loaded. | | $route['scaffolding_trigger'] = ’scaffolding’; | | This route lets you set a “secret” word that will trigger the | scaffolding feature for added security. Note: Scaffolding must be | enabled in the controller in which you intend to use it. The reserved | routes must come before any wildcard or regular expression routes. | */ $route['default_controller'] = “home”; $route['scaffolding_trigger'] = “”; // Customized routing rules $route['childmenu/([0-9]+)/([0-9]+)/([0-9]+)’] = “home/chidc/mid/$1/sid/$2/chid/$3″; /* End of file routes.php */ /* Location: ./system/application/config/routes.php */ ?>
Below we will go to the finished step for view -
// view.php <a href=”<?=base_url()?>childmenu/<?=$id1?>/<?=$id2?>/<?=$id3?>”>Menu name</a>
Tags: CodeIgniter, codeigniter uri routing rules, how to control query strings by uri rerouting, pass query strings by uri routing, rearrange url, routing rules, uri, uri rerouting, url, url rewrite, url segments reducing

Ahisq
May 1st, 2009
Hey thats good !
AndrewBoldman
June 4th, 2009
Hi, good post. I have been wondering about this issue,so thanks for posting.
admin
June 5th, 2009
@AndrewBoldman thanks for visiting my site
Kelly Brown
June 12th, 2009
Original post by Dmitri Gromov
CrisBetewsky
July 6th, 2009
Your site is worth beeing in the top cause it contains really amazing information.
Emile Criblez
April 28th, 2010
so this is certainly just what becomes of darwanism
atlanta cheap tickets
May 23rd, 2010
This is a great weblog posting and very useful. I truly appreciate the research you put into it
Top 100 Poems
May 27th, 2010
This really is my very first time i visit here. I discovered so many interesting stuff inside your blog especially its discussion. From the tons of comments on your articles, I guess I’m not the only one having all the enjoyment right here! maintain up the great function.
Top 100 Poems
May 28th, 2010
I have been searching looking around for this type of info. Will you post some a lot more in future? I’ll be grateful if you’ll.
Evelynn Reigel
May 29th, 2010
always be good if more people understood
Domain Parking
June 24th, 2010
Hi buddy, your blog’s model is simple and clean and i like it. Your blog content articles are superb. Please hold them coming. Greets!!!
Financial Tips
July 12th, 2010
Hey admin, very informative blog post! Pleasee continue this awesome work.
Melissa Bean
July 12th, 2010
awesome post
I’m definitely looking forward to seeing more posts!!!
Legal Sounds
July 16th, 2010
A thoughtful insight and ideas I will use on my blog. You’ve obviously spent some time on this. Thank you!
Cheap Rosetta Stone Chinese
August 30th, 2010
Good article, Each and every point is good enough.Thanks for sharing with us your wisdom.
King Stueber
August 31st, 2010
Sick of obtaining low numbers of useless traffic for your site? Well i wish to inform you of a new underground tactic which makes myself $900 on a daily basis on 100% AUTOPILOT. I really could be here all day and going into detail but why dont you merely check their website out? There is really a excellent video that explains everything. So if your seriously interested in making easy cash this is the site for you. Auto Traffic Avalanche