CodeIgniter / MAMP Pro : mapping URI param to default controller

老子叫甜甜 提交于 2019-12-08 11:31:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!