问题
I'm having an issue getting my rewrite rules to work. Here's what I get:
mysite:8888/ - works, but throws missing argument errors (expected)
mysite:8888/myvar - 404 error
mysite:8888/index.php/test/index/myvar - works and displays myvar on page (expected)
mysite:8888/test/index/myvar - 404 error
mysite:8888/test/myvar - 404 error
My routes.php file only contains:
$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 (controller):
public function index($myVar){
$data['myVar'] = $myVar;
$this->load->view('test', $myVar);
}
test.php (view):
<h1>Test page</h1>
<p>Here's your variable: <?=$myVar?>.</p>
and here's my .htaccess file (not even sure I need one):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
The goal is to have this URL: mysite:8888/hello
Generate this: "Here's your variable: hello."
What am I missing?
回答1:
Well, I figured it out. It turns out I had everything setup correctly, but the file headers on my .htaccess file were telling my Mac that it was a rich-text document. I pulled down a working .htaccess file from my web server, pasted the rewrite rules into it, and bingo! It started working. Thanks for the suggestion, everyone.
回答2:
I had some problems with rewrite on my mac the trick was to add
Options +FollowSymlinks
on the top of the htaccess file. Hope it will help cause i was getting access forbidden when i forgot to add.
来源:https://stackoverflow.com/questions/6144957/codeigniter-mamp-pro-mapping-uri-param-to-default-controller