I have controller named “profile” and the URL for user profile is www.example.com/profile/user
I am already using the rerouting of codeigniter in the routes file
If I understand your question correctly, you just want to add a catchall to the very end of your routes file. Like:
$route['(:any)'] = 'profile/index';
This will catch everything that isn't caught by another route, so make sure this script contains logic to determine when a 404 should be presented.