【问题标题】:CodeIgniter - Live site only loads index method for default controllerCodeIgniter - 实时站点仅加载默认控制器的索引方法
【发布时间】:2012-04-17 07:06:37
【问题描述】:

我一直在 Windows 7 上的 XAMPP 中开发 CodeIgniter 应用程序。 该应用程序在本地按预期运行,但在上传时却没有。

默认控制器(ShowStadium)有以下方法: - 指数() - 显示()

通过基本路径调用时索引加载正常,但直接调用时不会加载:

/pathToApp/ShowStadium/ 或 /pathToApp/ShowStadium/index 或 pathToApp/ShowStadium/show

收到的错误是 Codeigniter 404 消息。

codeigniter 实例当前位于 2 个子文件夹中。 我的 .htaccess 文件:

RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/

RewriteBase /proj/groundtweet/

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]

我尝试过的事情:

  • 控制器文件都是小写的。
  • 两个安装的基本路径都是正确的。
  • 尝试了各种 uri_protocol 选项
  • index.php 已从路径中删除。

任何帮助都将不胜感激,因为我找不到这个问题的具体答案,而且它可能很简单,令人沮丧。

如果我在这里遗漏了任何细节,我们深表歉意。

谢谢。

【问题讨论】:

  • 您的.htaccess 是否已解析?如果您将foobar 放在那里并将其作为第一行怎么办 - 您是否收到 500 错误请求?
  • @zerkms 刚刚尝试过,它确实会导致 500,因此正在解析 .htaccess。
  • 确保“控制器”文件夹已创建/可见,无论使用情况如何
  • 控制器文件夹的权限为 755。
  • 在访问您的函数时尝试包含index.php/index。如果它有效,那么您的.htaccess 文件肯定有问题。

标签: php codeigniter


【解决方案1】:

试试下面的代码,粘贴到 .htaccess 文件中。将此文件放在项目文件夹下 如果您的项目文件夹是groundtweet。将文件粘贴到此文件夹下。

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

我希望这会对你有所帮助..

【讨论】:

    【解决方案2】:

    转到 application/config/config.php 并更改

    $config['uri_protocol'] = 'AUTO';
    

    使用以下选项之一(在此配置上对其进行注释):

     'PATH_INFO'        Uses the PATH_INFO
     'QUERY_STRING' Uses the QUERY_STRING
     'REQUEST_URI'      Uses the REQUEST_URI
     'ORIG_PATH_INFO'   Uses the ORIG_PATH_INFO
    

    其中一个应该适合你

    【讨论】:

      【解决方案3】:

      感谢所有答案,最后是区分大小写的问题。

      控制器文件名是小写的 (showstadium.php),但在 Pascal 大小写 (ShowStadium) 中的表单操作中引用。

      似乎对于默认控制器/动作,CodeIgniter 可以解决这个问题(我没有看过胆量,所以我只是在这里做一个假设)但是当直接调用时,文件名必须匹配 url 大小写- 在 linux 服务器上。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-30
        • 1970-01-01
        • 2013-06-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多