How to remove controller name from the URL in codeigniter?

前端 未结 4 568
南笙
南笙 2020-12-20 03:00

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

4条回答
  •  失恋的感觉
    2020-12-20 03:46

    You may try any one of these

    // url could be yourdomain/imran
    $route['(:any)'] = 'profile/index/$1';
    // url could be yourdomain/10
    $route['(:num)'] = 'profile/index/$1';
    // url could be yourdomain/imran10
    $route['([a-zA-Z0-9]+)'] = "profile/index/$1";
    

    Your class may look like this

    class Profile extends CI_Controller {
    
        public function index($id)
        {
            // $id is your param
        }
    }
    

    Update : (Be careful)

    Remember that, if you have a class Someclass and you use url like yourdomain/Someclass then this will be routed to profile/index/$1 if you have $route['(:any)'] or $route['([a-zA-Z0-9]+)'].

提交回复
热议问题