开发者

CodeIgniter / MAMP Pro : mapping URI param to default controller

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: m开发者_如何学Cysite:8888/hello

Generate this: "Here's your variable: hello."

What am I missing?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜