Home » Php » php – How to hide controller name in the url in CodeIgniter?

php – How to hide controller name in the url in CodeIgniter?

Posted by: admin July 12, 2020 Leave a comment

Questions:

so the thing is I’m using .htaccess to hide the index.php but I still get the controller name in the url like that: http://example.com/name_controller/about
My question is: is it possible to hide the name of the controller, so that only method is shown? hxxp://example.com/name_controller/about

How to&Answers:

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

See Hiding the controller’s method name in the URL? in the CI forums for more information.

Answer:

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

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

Answer:

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.

Answer:

$route[‘default_controller’] = “xxx”;

home

$route[‘home‘] = “xxx/home“;

function_name/parameter0/parameter1/parameter2

$route[‘Collection/(:any)‘] = “xxx/Collection/$1“;

Answer:

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";//search product list perameters.

100% It work..