user image

Eslam Zedan
Published in : 2022-02-22

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 Date : 2022-02-22

Best answers

8

Best answers

8

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.

Eslam Zedan Date : 2022-02-23

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

Yasen Sayed Date : 2022-02-23

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 Date : 2022-02-23

Best answers

8

Best answers

8

Thank you that work fine

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

ERROR 1410 (42000): You are not allowed to create a user with GRANT
Publish date: 2022-04-01 | Comments: 2

Tag: PHP & Mysql

SQL full languages table
Publish date: 2022-02-24 | Comments: 2

Tag: PHP & Mysql

php difference between two times in hours
Publish date: 2022-02-25 | Comments: 2

Tag: PHP & Mysql

mysql service start not exist
Publish date: 2022-02-23 | Comments: 4

Tag: PHP & Mysql

[solved] Storage engine 'InnoDB' does not support system tables
Publish date: 2022-01-09 | Comments: 0

Tag: PHP & Mysql

change user root privelige and password
Publish date: 2022-02-23 | Comments: 1

Tag: PHP & Mysql

[solved] #1273 - Unknown collation: 'utf8mb4_0900_ai_ci'
Publish date: 2022-01-09 | Comments: 1

Tag: PHP & Mysql

PHP mail function goes to spam not inbox
Publish date: 2022-02-28 | Comments: 2

Tag: PHP & Mysql