Search code examples
codeigniterurluricodeigniter-url

Codeigniter - retrieve parameter without controller name in URL


I'm trying to retrieve string as parameter using following URL scheme: www.myapp.com/[String]

Is there any way I can do this?

*Based on my research, Codeigniter doesn't accept string parameters unless I include the Controller's name in URL: www.myapp.com/[Controller Name]/[String] But this doesn't solve my problem :(


Solution

  • You're right, CI requires controller name at URI, but You can use default_controller.

    At config/routes.php add route rule $routes['(:any)'] = 'welcome/index';, remove index.php from Your URL (there're many tutorials and how-to for this), and at last useuriclass at Yourindex()method ofwelcome` controller:

    function index(){
        var_dump($this->uri->uri_string());
    }