我遇到了让我的重写规则发挥作用的问题。下面是我得到:CodeIgniter/MAMP Pro:将URI参数映射到默认控制器
的mysite:8888/- 作品,但抛出缺少的参数错误(预期)
的mysite:8888/MYVAR - 404错误
的mysite:8888/index.php文件/测试/索引/ MYVAR - 作品和显示MYVAR页(预期)
的mysite:8888 /测试/索引/ MYVAR - 404错误 的mysite:8888 /测试/ MYVAR - 404错误
我routes.php文件文件只包含:
$route['default_controller'] = "test";
config.php:
$config['base_url'] = 'http://mysite:8888/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
test.php的(控制器):
public function index($myVar){
$data['myVar'] = $myVar;
$this->load->view('test', $myVar);
}
test.php的(视图):
<h1>Test page</h1>
<p>Here's your variable: <?=$myVar?>.</p>
,这里是我的.htaccess文件(甚至不知道我需要一个):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
目标是让这个网址:mysite:8888 /你好
生成此:“这是你的变量:你好。”
我错过了什么?
你试过mysite:8888/test/myvar /? – Chumillas 2011-05-26 21:07:19
我敢打赌,你的htaccess文件设置不正确 - 有道理看到,当你在url中使用index.php时,一切正常 – jpea 2011-05-27 04:35:48
试试RewriteBase /在刚才在RewriteEngine下的htaccess文件中 – jpea 2011-05-27 04:42:42