不存在 URI.默认控制器集.Codeigniter 3.1.9 和 PHP 7.0



我的路由不起作用。

我删除了索引.php - https://github.com/bcit-ci/CodeIgniter/wiki/Removing-index.php-from-a-URL-path-in-XAMPP-for-Windows

我正在使用以下设置。 代码点火器 3.1.9 的新副本

配置.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>

路线.php

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

控制器 - 您好.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');
}
}

当我导航到 http://localhost/CodeIgniter-3.1.9/hello 时,它正在加载欢迎控制器。

原木

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

> 删除base_url末尾的斜杠

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

这是我的错,我在配置中打开了$config['enable_query_strings'] = TRUE;,这就是它导致问题的原因。当我读取核心 uri.php 文件时,它有以下注释。

// 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)

我设置$config['enable_query_strings'] = FALSE;然后一切正常。

最新更新