How to hide controller name in CodeIgniter url?

How to hide controller name in CodeIgniter url?

How to hide controller name in CodeIgniter url?

Hello Guys, 

So here is a problem when we are using urls in Codeigniter and we want to short our urls for SEO Friendly URLS then we hide some portions of URL and short our urls.

Here are some examples to hide controller name in CodeIgniter url and short our urls.

 

1. First Example:

You can define a custom route in config/routes.php - for example:

$route['about'] = 'name_controller/about';

Then, http://example.com/about

goes to http://example.com/name_controller/about

 

2. Second Example:

You can add an entry in the /system/application/config/routes.php file:

$route['about'] = "controller_name/about";

I did it like this: (config/routes.php)

Code: $route['((photos|blogs).+)'] = "$1";

$route['([a-zA-Z0-9_-]+)'] = "user/profile/$1";

it is ok correct solutions for common.

$route['default_controller'] = "xxx";

home

$route['home'] = "xxx/home";

function_name/parameter0/parameter1/parameter2

$route['Collection/(:any)'] = "xxx/Collection/$1";

 

3. Third Example:

You can add below code in the /application/config/routes.php file:

$route['default_controller'] = "Home";

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

$route['translate_uri_dashes'] = FALSE;

 

$route['(?i)about'] = "Home/about";

$route['(?i)login'] = "Home/Login";

$route['(?i)products'] = "ProductController/ProductList";

$route['(?i)addproduct'] = "ProductController/AddProduct";

$route['(?i)editproduct'] = "ProductController/EditProduct";

$route['(?i)products/(:any)'] = "ProductController/ProductList/$1";

Enjoyed this article? Stay informed by joining our newsletter!

Comments

You must be logged in to post a comment.

About Author
Popular Articles
Jun 2, 2020, 4:01 AM - Shahzad Alam
Jan 30, 2020, 7:50 AM - Sajjad Ahmad
May 7, 2020, 10:39 AM - Maryam Qureshi
May 17, 2020, 2:25 AM - Raees Khan
May 29, 2020, 5:44 PM - Shahzad Alam