Hi guys please advice me as Code igniter 3.1.11 router.php is not working
Its only working for http://maindomain/
but not working for http://maindomain/about instead shows 404 page
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
.htaccess file below
RewriteEngine on
RewriteCond $1 !^(index.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
# php -- BEGIN cPanel-generated handler, do not edit
# This domain inherits the “PHP” package.
# php -- END cPanel-generated handler, do not edit
2
Answers
$route['(:any)'] = 'pages/view/$1';
will redirect all your requests topages/view
irrespective of whatcontroller(URL)
you write and will be a nightmare to manage all the requests to your site.Say, you write
http://maindomain/xyz/something
now because it doesn’t expect any parameter after(:any)
, it goes to404
but
http://maindomain/xyz
will work fine as it satisfies your routing rule.The reason
http://maindomain
works is because you’ve defined it as your default controller. You can write yourroutes
like this –See if it helps you.
This looks like a similar issue I had and I ended up fixing it by editing system/core/Router.php and changing line 396 from:
to
… not ideal because it isn’t upgrade safe but it did the trick for me (CI 3.1.11, PHP 7.4)