user

Eslam Zedan

22 Feb 2022

CodeIgniter route does not work

PHP & Mysql

Hello, 

I am working on old CodeIgniter 2 project I added a new route to application/config/routes.php 

here is the new file:

$route['products'] = 'products/index';
$route['product/(:num)'] = 'products/single/$1';
$route['(:any)'] = 'pages/$1';
$route['product/(:any)'] = 'products/search/$1';

$route['default_controller'] = "home";
$route['404_override'] = '';

 

the request does not go to Products class, it returns 404 not found 

Here is my controller:

<?php
class Products extends CI_Controller {

 public function index()
 {
 #### Some Code ####
 }
 
 public function single($id)
 {
 #### Some Code ####
 }
 
 public function search($text)
 {
 #### Some Code ####
 }
}

Any help,

Thanks

Comments

Yasen Sayed

22 Feb 2022

Best Answer

best answer

Hey, Please try this approach add index.php before your route name for example:

 

'localhost:8080/products/index.php/index'

I think the problem is from the .htaccess file.

Replies

Eslam Zedan

23 Feb 2022

No that is not the problem, every other route is working fine

Yasen Sayed

23 Feb 2022

I find the problem in the route order.

 

$route['products'] = 'products/index';
$route['product/(:num)'] = 'products/single/$1';
$route['product/(:any)'] = 'products/search/$1';
$route['(:any)'] = 'pages/$1';
$route['default_controller'] = "home";
$route['404_override'] = '';

Eslam Zedan

23 Feb 2022

Thank you that work fine

© 2024 Copyrights reserved for web-brackets.com