【问题标题】:CodeIgniter / MAMP Pro : mapping URI param to default controllerCodeIgniter / MAMP Pro:将 URI 参数映射到默认控制器
【发布时间】: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


【解决方案1】:

好吧,我想通了。事实证明我的所有设置都正确,但我的 .htaccess 文件上的文件头告诉我的 Mac 这是一个富文本文档。我从我的 Web 服务器上下载了一个工作的 .htaccess 文件,将重写规则粘贴到其中,然后宾果游戏!它开始工作了。谢谢大家的建议。

【讨论】:

    【解决方案2】:

    我在我的 mac 上重写时遇到了一些问题,诀窍是添加

    选项 +FollowSymlinks

    在 htaccess 文件的顶部。希望这会有所帮助,因为当我忘记添加时,我被禁止访问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      相关资源
      最近更新 更多