codeigniter default controller url routing

假如想象 提交于 2019-12-01 00:19:27
Ahmad

you should add the following rule in your config/routes.php

// Profile Route
$route['(:any)'] = 'home/$1';

this will reroute all your request to the home controller.

so domain/michelle will re be rerouted as domain/home/michelle but in this case all your requests will be rerouted to the home controller eg. domain/pages/about will also be rerouted to domain/home/pages/about wich false.

domain/michelle => domain/home/michelle // TRUE
domain/pages/about => domain/home/pages/about // FALSE

so you MUST add for each request a identic rule before the Profile Route, eg. $route['pages/(:any)'] = 'pages/$1';

put it all together :

// Page Route 
$route['pages/(:any)']  = 'pages/$1'

// Last Profile Route
$route['(:any)'] = 'home/$1';

This is not the easiest thing to do in Codeigniter. To do so you need first you need to define all the routes you use in routes.php and to the end of file you need to add line, that will send all other requests to your controller that will check if user exists.

$route['stores/(:any)'] = 'stores/$1';
$route['pages/(:any)'] = 'pages/$1'; 

$route['(:any)'] = "home/$1"; //this route will return user's page

You can do this by modifying the routes.php file available in application/config file. To learn more about routes.php. Here is the link URI routing in Codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!