What is routing in CodeIgniter?

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPin on PinterestPrint this pageEmail this to someone

URL Routing In Php CodeIgniter
URLs in CodeIgniter are intended to be short and web index agreeable. It should sound good to the guests. A client ought to get a thought regarding the page content through its URL.
For example, http://abc.com/codeigniter/routing_url
The above URL example makes more sense and gives a brief idea to the users what it is about.
One should always go for the SEO friendly URL.
URL routing is a technique through which it converts SEO friendly URLs into a server code format that understands it easily and drives a request to corresponding handler scripts.
Setting your own Routing Rules
Steering rules are characterized in routes.php record at the area application/config. In this document you’ll see $route cluster, it licenses you to determine your own particular steering criteria. Courses can be characterized in two ways, either utilizing Wildcards or Regular Expressions.
Wildcards
There are two types of wildcards:

1
2
3
4
:num−series containing only numbers will be matched.
:any−series containing only characters will be matched.
Using :num
$route['(blog/:num)'] = 'women/social/$1';

URL containing first segment as ‘blog’ and second segment as any ‘number’ will represent to the URL containing ‘women’ class and ‘social’ method passing in the match as the variable to the function.
It means when we’ll pass URL http://www.abc.com/blog/1
Note: Here, you can pass any number instead of 1 in the URL.
It will be directed to http://www.abc.com/women/social

1
2
Using :any
$route['(blog/:any)'] = 'women/social';

URL containing first segment as ‘blog’ and second segment as anything will represent to the URL containing ‘women’ class and ‘social’ method.
It means when we’ll pass URL http://www.abc.com/blog/xyz
Note: Here, you can pass anything in the last segment of URL.
It will be directed to http://www.abc.com/women/social
Regular Expression
Regular expressions are also used to redirect routes.

You can create your own regular expression to run your URL.
URL Suffix
To add a suffix in your URL, go to file config.php in application/config folder and add suffix you want as shown below. We have added .jsp as the suffix.

1
2
3
$config['url_suffix'] = '.html';
For example, if our URL ishttp://www.abc.com/women/social
Then after adding suffix, our URL will becomehttp://www.abc.com/women/social.html
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPin on PinterestPrint this pageEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *