我的路由不起作用。
我用-https://github.com/bcit-ci/CodeIgniter/wiki/Removing-index.php-from-a-URL-path-in-XAMPP-for-Windows
删除了index.php。我正在使用以下设置: 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
答案 0 :(得分:0)
删除base_url
末尾的斜杠
$config['base_url'] = 'http://localhost/CodeIgniter-3.1.9';
答案 1 :(得分:0)
那是我的坏事,我在配置中打开了$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;
,然后一切正常。