I have a CI routes.php as below.
$route['default_controller'] = "site";
$route['404_override'] = 'site';
$route['admin'] = 'admin';
$route[':any'] = 'site/user';
The thing required is when any user name (which I will check with database) is typed with URL like - localhost/CIproj/username
then it should go to site/user
controller.
If 'admin' is there in URL like - localhost/CIproj/admin
it will go to admin
controller (index function). URL will change to localhost/CIproj/admin/dashboard
.
So the error I am getting is when I go to localhost/CIproj/admin
, I get login screen. But after login it will go to admin/dashboard
. This is where I get redirected to site/user
.
Then I tried with below one.
$route['user/(:any)'] = 'site/user';
And now everything was working. But the URL will be like - localhost/CIproj/user/username
.
So the question is , is there any way where I don't have to write user
in the URL. Visitors can type anything in the URL.
localhost/CIproj/anything
if anything== username from database
it will go to site/user
.
if anything== admin or any of its page
it will go to respective controllers.
Or else 404pagenotfound.php.
Note: Admin is a huge module with many controllers. So I don't think I should write routes for every of admin controller here.