【发布时间】:2021-03-13 15:20:36
【问题描述】:
我想从默认控制器上的 url 中捕获参数,但它给 ma 一个错误 404 page not found.
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
localhost:/myproject => 这正在加载我的默认控制器及其视图,但是当我尝试 localhost:/myproject/pa8989 => 这给了我 404 page not found 错误。
.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 错误呢?
【问题讨论】:
标签: php .htaccess codeigniter