PHP Codeigniter URL Routing Automatically

PHP Codeigniter URL Routing Automatically

Today, We want to share with you PHP Codeigniter URL Routing Automatically.
In this post we will show you Codeigniter URL Routing Example, hear for php – Routes in Codeigniter – Automatically we will give you demo and example for implement.
In this post, we will learn about CodeIgniter URL Security And URL Routes with an example.

In codeigniter(CI), PHP files are served in a (different Nav linked)different way rather than (used view,controller(MVC))accessing the all PHP files directly used from the browser(Mozila,chrome,etc..).
This process or structure is called as Routing(one-to-one).

There is a process of one-to-one create a relationship between a two URL string and it is corresponding (nav linked) controller class/method(define and check using MVC)

By default routes in, URLs in CodeIgniter(CI) are designed to be one-to-one search-engine(Like Google,yahoo) and user-human friendly navigation.
Through this user show all contents actually knows what contents a page (Like home,aboutus,contactus.etc..)contains just by checking all the pages the URL in the all browser’s address bar search.
so,an URL Routing is a one technique which converts to easy way to navigation these SEO friendly urls(in search engine) to a format that easy way to server code can understand easily to user and drives a all the request to their check corresponding all request handler scripts.

Read Also:  How to Check ruby Version by CLI and File?

***Setting All Rules For (CI)CodeIgniter URI Routing Step By Step***

File Path : application/config/routes.php

open this routes.php file and it’s located in application/config folders.

There are mostly used two types of wildcards with example, namely here display:

1st – :num – It is a Segment containing data only check numbers(Like 1,2,3,4,5,6,etc..) will be matched and routes.
2nd – :any – It is a Segment containing data only check characters(Like A – Z,or name) will be matched and routes.

Read Also:  create rest api php mysql - PHP 8 CRUD REST API with MySQL & PHP PDO Example

Using :num : wildcards num in codeigniter

$route['(myfirstblog/:num)'] = 'tutorialpakainfo/vuejs/$1';

Using :any : wildcards any in codeigniter

$route['(myfirstblog/:any)'] = 'tutorialsng/Angularjs';

Example of Regular Expression using codeigniter

$route['myfirstblog/([a-zA-Z0-9]+)'] = 'application/laravel';

Example of URL Suffix using codeigniter

$config['url_suffix'] = '.html'; //html file
$config['url_suffix'] = '.php'; //PHP file

Setting your own routing rules – URL Enabled Query String

In order to use simple the Query String URL’s,and this file edit config.php display the
which is located in this folders path application/config/config.php.
and Set the config ‘enable_query_strings’ boolean value to TRUE and define just controller and the function trigger in config file.

Read Also:  Multiselect dropdown with checkboxes demo code in php

$config['enable_query_strings'] = TRUE; // boolean value true or false
$config['controller_trigger'] = 'c'; //controller of trigger
$config['function_trigger'] = 'm'; // trigger of function

codeigniter url – Reserved Routes – codeigniter

There are following two types of reserved routes using CI:

1st : 

$route['wel_defaultpage_controller'] = 'welcome_page';
2nd :

$route['404_override'] = '';

codeigniter url routing Example : 1

$route['page-aboutusdata'] = "pageaboutusd";
$route['new-where-well-areu'] = "wherewearesss";
$route['(:any)'] = "polica/twist/$1";

codeigniter url routing Example : 2

Pakainfo.com/salesorder/1/
Pakainfo.com/salesorder/2/
Pakainfo.com/salesorder/3/
Pakainfo.com/salesorder/4/ 

codeigniter url routing Example : 3

$route['defaultpage/(:any)'] = "homemenu/defaultpage/$1";
$route['defaultpage'] = "homemenu/index";
$route['(:any)/defaultpage/(:any)'] = "homemenu/categorylist/$1/defaultpage/$2";
$route['(:any)/defaultpage'] = "homemenu/categorylist/$1";
$route['defaultpage'] = "homemenu/index";

$route['(:any)/(:any)'] = "homemenu/titlenav/$2";
$route['(:any)'] = "homemenu/categorylist/$1";