尝试访问 CodeIgniter 中的现有控制器时给出 404
我正在安装相当新的 CodeIgniter 2.0。
我有一个包含此代码的 htaccess 文件
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
转到 URL http://www.estiem.no/ESTIEM /CI/ 有效, 但是http://www.estiem.no/ESTIEM/CI/site/index 没有。它给出了 404。控制器站点存在,并且包含方法“index”
您知道可能有什么问题吗?
I am working on a fairly new install of CodeIgniter 2.0.
I have a htaccess-file containg this code
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Going to the URL http://www.estiem.no/ESTIEM/CI/ works,
but http://www.estiem.no/ESTIEM/CI/site/index does not. It gives a 404. The controller Site exists, and contains the method 'index'
Any ideas what might be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要从index.php中删除/
You need to remove / from index.php
这是一个 htaccess 问题,当每个人都传递该代码时,我们发现很多主机不喜欢它,你可以用 ? 来破解它。或这样或那样,直到它最终看起来像一个拼图游戏(情况就是这样),但是使用出色的htaccess(不确定第一个是谁,但好像有500个已经获得了荣誉),你将永远不必再次更改它(好吧不是永远)但它在未编辑的情况下 99% 的情况下都能工作):
相信我,我也遇到过同样的问题,并且在我应该来这里甚至 CI wiki 的时候花了几个小时在 google 上(因为这是我第一次看到它的地方),你不敢相信仅仅用那么一点 htaccess 就能在 CI 中解决多少问题。他们确实应该将其添加到存储库中。
It is a htaccess problem, back when everyone passed that code around we found that a lot of hosts didn't like it and you could hack it with a ? or this or that until it ended up looking like a jigsaw puzzle (the condition that is) but using a brilliant htaccess (not sure who the first was but like 500 have taken credit) you will never have to change it again (well not never but it will work 99% of the time un edited):
Trust me I have had the same issues and spend hours on google when i should have come here or even the CI wiki (since that is the first place I seen it), you would not believe how many issues are solved in CI with just that bit of htaccess. they really should add it to the repo.
我刚刚注意到,由于您将 CI 安装在子文件夹中,因此您需要在
.htaccess
重写中考虑到这一点:所以你的
.htaccess
看起来像:这应该修复它(抱歉晚编辑,由于 @BrianOrtiz 的评论)
I just noticed that since you have your CI install in a subfolder, you need to account for that in the
.htaccess
rewrite:So your
.htaccess
will look like:That should fix it (sorry late edit, due to @BrianOrtiz 's comment)
尝试使用以下方式访问控制器: localhost/site/index.php/controller
如果这不起作用,可能是因为 CI 区分大小写
否则
将被命名为
mycontroller.php
控制器文件夹如果所有其他方法都失败,请用以下内容替换您的 htaccess:
Try to access the controller with: localhost/site/index.php/controller
If that does not work maybe because the CI is case sensitive
else
will be named
mycontroller.php
in the controllers folderIf all else fails replace your htaccess by this: