【发布时间】:2011-09-02 22:48:09
【问题描述】:
我在让我的重写规则生效时遇到问题。这是我得到的:
mysite:8888/ - 有效,但抛出缺少参数错误(预期)
mysite:8888/myvar - 404 错误
mysite:8888/index.php/test/index/myvar - 工作并在页面上显示 myvar(预期)
mysite:8888/test/index/myvar - 404 错误
mysite:8888/test/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/hello
生成这个:“这是你的变量:你好。”
我错过了什么?
【问题讨论】:
-
你试过 mysite:8888/test/myvar/ 吗?
-
我敢打赌你的 htaccess 文件没有正确设置——当你在 url 中使用 index.php 时,一切正常
-
在 RewriteEngine 下的 htaccess 文件中尝试 RewriteBase /
-
@Chumillas,是的,我试过了,但收到 404 错误。
-
@jpea - 我刚刚添加了那行,结果是一样的。
标签: url codeigniter mod-rewrite uri mamp