我遇到了讓我的重寫規則發揮作用的問題。下面是我得到: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