Hari Inukollu
Hari Inukollu

Reputation: 179

No URI present. Default controller set. Codeigniter 3.1.9 and PHP 7.0

My routing is not working.

I removed the index.php with - https://github.com/bcit-ci/CodeIgniter/wiki/Removing-index.php-from-a-URL-path-in-XAMPP-for-Windows

I am using the following settings. Fresh copy of Codeigniter 3.1.9

config.php

$config['base_url'] = 'http://localhost/CodeIgniter-3.1.9/';
$config['index_page'] = '';

.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

routes.php

$route['hello/(:any)'] = 'hello/$1';

controller - Hello.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Hello extends CI_Controller {

    public function __construct(){
        parent::__construct();
    }
    public function index()
    {
        echo("Hello - index");
        $this->load->view('welcome_message');
    }

    public function hello(){
        echo("hello");
        $this->load->view('welcome_message');
    }
}

When I navigate to http://localhost/CodeIgniter-3.1.9/hello it's loading the Welcome controller.

Logs

DEBUG - 2018-08-24 18:56:47 --> UTF-8 Support Enabled
DEBUG - 2018-08-24 18:56:47 --> No URI present. Default controller set.
DEBUG - 2018-08-24 18:56:47 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2018-08-24 18:56:47 --> Total execution time: 0.0227

Upvotes: 0

Views: 1062

Answers (2)

Hari Inukollu
Hari Inukollu

Reputation: 179

That's my bad, I turned on $config['enable_query_strings'] = TRUE; in config that's why it's causing the issue. When I was reading the core uri.php file then it has following comment.

// If query strings are enabled, we don't need to parse any segments.
        // However, they don't make sense under CLI.
        if (is_cli() OR $this->config->item('enable_query_strings') !== TRUE)

I set $config['enable_query_strings'] = FALSE; then everything working fine.

Upvotes: 0

lcssanches
lcssanches

Reputation: 1014

Remove the slash at the end of base_url

$config['base_url'] = 'http://localhost/CodeIgniter-3.1.9';

Upvotes: 0

Related Questions