尝试访问 CodeIgniter 中的现有控制器时给出 404

发布于 2024-10-20 11:32:45 字数 477 浏览 3 评论 0原文

我正在安装相当新的 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 技术交流群。

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

发布评论

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

评论(4

小瓶盖 2024-10-27 11:32:45

您需要从index.php中删除/

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

You need to remove / from index.php

RewriteRule ^(.*)$ index.php/$1 [L]
╰ゝ天使的微笑 2024-10-27 11:32:45

这是一个 htaccess 问题,当每个人都传递该代码时,我们发现很多主机不喜欢它,你可以用 ? 来破解它。或这样或那样,直到它最终看起来像一个拼图游戏(情况就是这样),但是使用出色的htaccess(不确定第一个是谁,但好像有500个已经获得了荣誉),你将永远不必再次更改它(好吧不是永远)但它在未编辑的情况下 99% 的情况下都能工作):

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>  

相信我,我也遇到过同样的问题,并且在我应该来这里甚至 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):

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>  

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.

彼岸花似海 2024-10-27 11:32:45

我刚刚注意到,由于您将 CI 安装在子文件夹中,因此您需要在 .htaccess 重写中考虑到这一点:

/ESTIEM/CI/

所以你的 .htaccess 看起来像:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ESTIEM/CI/index.php/$1 [L]

这应该修复它(抱歉晚编辑,由于 @BrianOrtiz 的评论)

I just noticed that since you have your CI install in a subfolder, you need to account for that in the .htaccess rewrite:

/ESTIEM/CI/

So your .htaccess will look like:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ESTIEM/CI/index.php/$1 [L]

That should fix it (sorry late edit, due to @BrianOrtiz 's comment)

孤者何惧 2024-10-27 11:32:45

尝试使用以下方式访问控制器: localhost/site/index.php/controller

如果这不起作用,可能是因为 CI 区分大小写

  • localhost/site/controller == c :...\site\controller.php
  • localhost/SITE/controller == c:...\SITE\controller.php

否则

<?php

controller Mycontroller extends Controller {

}

?>

将被命名为 mycontroller.php控制器文件夹


如果所有其他方法都失败,请用以下内容替换您的 htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Try to access the controller with: localhost/site/index.php/controller

If that does not work maybe because the CI is case sensitive

  • localhost/site/controller == c:...\site\controller.php
  • localhost/SITE/controller == c:...\SITE\controller.php

else

<?php

controller Mycontroller extends Controller {

}

?>

will be named mycontroller.php in the controllers folder


If all else fails replace your htaccess by this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文