在 Codeigniter 中,有些 URI 通过 index.php,有些则不通过

发布于 2024-11-04 22:52:12 字数 579 浏览 0 评论 0原文

基本上一个控制器(controller/topics.php, http://192.168.1.50/topics)通过 CI 的索引传递.php 就像它想象的那样,还有另一个(controller/user.php,http://192.168.1.50/user )由于某些奇怪的原因根本无法通过(我在浏览器中收到 404 错误)。 CodeIgniter 和/或 Apache2 正在做一些奇怪的事情,我无法弄清楚:“.../user”给了我 Apache 的 404 页面,而“.../User”给了我 CI 的 404 页面,这意味着 CI 抓取 URI大写控制器名称并忽略一些具有小写控制器名称的 URI(然后 Apache 尝试处理该 URI)。

有什么想法为什么以及如何解决吗?

PS - 是的,我确实在 CI 论坛上发布了我的问题,但我没有得到他们的帮助。我在 Linux 发行版(带 LAMP 的 Ubuntu 10.10)上运行 CodeIgniter 2.0.2。

Basically one controller (controller/topics.php, http://192.168.1.50/topics) gets passed through CI's index.php like its suppose to, yet another (controller/user.php, http://192.168.1.50/user) for some odd reason simply doesn't pass (I get an 404 error in browser). CodeIgniter and/or Apache2 are doing something funky and I can't figure it out: '.../user' gives me Apache's 404 page, yet '.../User' gives me CI's 404 page which means CI grabs URIs with uppercase controller names and ignores some URIs with lowercase controller names (and then Apache tries to handle the URI).

Any ideas why and how to resolve?

P.S. - Yes, I did post my issue in CI's forum but I'm not having luck with their help. I'm running CodeIgniter 2.0.2 on a Linux distro (Ubuntu 10.10 with LAMP).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜深人未静 2024-11-11 22:52:12

问题是重写条件语法表示不要路由以 i、c、j 或 u 开头的文件夹,而不是名称为 i、c、j 或 u 的文件夹。巧合的是,我未加载的控制器名称以 i(想法)和 u(用户)开头。

我可以将静态文件夹重命名为其全名(“uploads”而不是“u”)并更新重写条件并解决此问题,但我想保持名称相同。有人碰巧知道重写条件的正确语法以匹配确切的名称(而不是像或开头)?

The problem was that the rewrite condition syntax is saying don’t route folders that BEGIN with i, c, j or u instead of folders whose name IS i, c, j or u. Coincidently my controller names which weren’t loading started with i (idea) and u (user).

I could just rename my static folders to their full names (“uploads” instead of “u”) and update the rewrite condition and resolve this issue, but I’d like to keep the names the same. Anyone happen to know the correct syntax for the rewrite condition to match exact names (instead of like or begins with)?

2024-11-11 22:52:12

检查你的控制器名称,人们(我发现)最常见的事情就是复制他们的“主”控制器(比如topics.php)并将文件名重命名为 whatever.php

他们开始开发控制器名称仍为“主题”。由于找不到控制器(不是实际文件)而抛出 404

错误:
class Blog extends CI_Controller {...

如果上述代码位于名为 stuff.php 的文件中。如果您调用 /stuff,您将收到 404

Check your controller name, the most common thing people (I find) do is copy their 'main' controller (say topics.php) and rename the file name to whatever.php

They start developing and the controller name stays 'Topics'. 404 is thrown due to the controller not being found (not the actual file)

ex:
class Blog extends CI_Controller {...

if the above code is in a file called stuff.php. You will get a 404 if you are calling /stuff

匿名。 2024-11-11 22:52:12

我昨天遇到了类似的问题。默认控制器可以具有大写文件名,但任何其他控制器在大写时都会生成 404。这是在 MAMP 设置上。

确保您的控制器也反映文件名。

class User extends CI_Controller {

I ran into a similar problem yesterday. The default controller can have an uppercase file name but any other controller would produce a 404 when uppercase. This was on a MAMP setup.

Make sure your controller reflects the file name as well.

class User extends CI_Controller {
舞袖。长 2024-11-11 22:52:12

在你的 htaccess 中...而不是

RewriteRule ^(.*)$ /index.php/$1 [L]

尝试

RewriteRule ^(.*)$ index.php/$1 [L]

并在 CI 配置中按照指示设置 base_url(包括尾随 /!)

$config['base_url'] = 'http://www.site.com/';

应该可以了。

in your htaccess... instead of

RewriteRule ^(.*)$ /index.php/$1 [L]

try

RewriteRule ^(.*)$ index.php/$1 [L]

and in your CI config set base_url as instructed (include trailing /!)

$config['base_url'] = 'http://www.site.com/';

That should do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文