我想从默认控制器上的url中捕获参数,但它给了ma一个错误404,找不到页面。
routes.php
$route['default_controller'] = 'MainBrain';
$route['MainBrain/(:any)'] = "MainBrain/index/$1";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
MainBrain.php
class MainBrain extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function index() {
echo 'Parameter value - ' . $this->uri->segment(3);
$this->load->view('index', $data);
}
}
现在每当我尝试加载url时CCD_ 1=>这正在加载我的默认控制器及其视图,但当我尝试localhost:/myproject/pa8989
=>这给我404页找不到错误。
.htaccess:
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
那么,如何从默认参数中获取参数,而不是404错误呢?
如果您希望localhost:/myproject/pa8989路由到您的函数,那么您需要更改路由:
$route['MainBrain/(:any)'] = "MainBrain/index/$1";
至
$route['(:any)'] = "MainBrain/index/$1";
否则,您需要通过localhost:/myproject/mainbrain/pa89899访问该功能