【问题标题】:Codeigniter - no input file specifiedCodeigniter - 没有指定输入文件
【发布时间】:2011-09-01 09:39:42
【问题描述】:

我是 Codeigniter 的初学者,我看过一个 CI 教程,只是想做一件简单的事情。我下载了 CI 并将这个文件添加到控制器目录,但它不起作用。

<?php

class site extends CI_Controller
{
    public function index()
    {
        echo "Hello World";
    }

    function dosomething()
    {
        echo "Do Something";
    }   
}    
?>

当我尝试使用http://..../index.php/site 访问它时,我得到了输出……“没有指定输入文件”……顺便说一句,我将文件命名为 site.php

【问题讨论】:

  • 尝试检查this link,看看它是否能解决问题。
  • 没有帮助感谢您的努力

标签: codeigniter php


【解决方案1】:

只需在 .htaccess 文件中的 index.php 之后添加 ? 符号即可:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

它会起作用的!

【讨论】:

  • 对我来说,这是一个 301 重定向,我最终在 URL 中使用 /?/。
  • @Ali Mohamed,您在哪个 htaccess 文件中添加了这一行?我试过但没有任何效果
  • @Bahdeng 您需要将此 sn-p 放在项目目录中的 .htaccess 文件中。
  • 根据您的应用程序目录更改上面的行,如果您的应用程序不在根目录上,请编写以下代码代替上面的行RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
  • @NSGodMode 将位于 index.php 之外的 codeigniter 根目录中
【解决方案2】:

Godaddy 托管它似乎固定在 .htaccess,我自己它正在工作

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

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

【讨论】:

  • 根据您的应用程序目录更改上面的行,如果您的应用程序不在根目录上,请编写以下代码代替上面的行RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
  • 在 CI 3 中找不到 404 页面
【解决方案3】:

我在这里找到了这个问题的答案......问题是托管服务器......我感谢所有尝试过的人......希望这对其他人有帮助

Godaddy Installation Tips

【讨论】:

  • 根据您的应用程序目录更改上面的行,如果您的应用程序不在根目录上,请编写以下代码代替上面的行RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
【解决方案4】:

CodeIgniter 应用的 .htaccess 文件中的 RewriteEngine、DirectoryIndex

我刚刚更改了 .htaccess 文件内容,如以下links 答案所示。并尝试刷新页面(它不起作用,并且找不到对我的控制器的请求)它起作用了。

然后只是因为我的怀疑,我撤消了我对 public_html 文件夹中的 .htaccess 所做的更改,恢复为原始 .htaccess 内容.所以现在是这样的(原来是这样的):

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]

现在它也可以工作了。

提示:似乎在服务器上下文中尚未明确设置重写规则之前。

我的文件结构如下:

/
|- gheapp
|    |- application
|    L- system
|
|- public_html
|    |- .htaccess
|    L- index.php

并且在index.php我已经设置了以下路径到系统和应用程序:

$system_path = '../gheapp/system';
$application_folder = '../gheapp/application';

注意:这样做,我们的应用程序源代码首先会向公众隐藏。

如果你们发现我的回答有任何问题,请发表评论并重新纠正我!
希望初学者会觉得这个答案很有帮助。

谢谢!

【讨论】:

    【解决方案5】:

    我的网站托管在 MochaHost 上,我很难设置 .htaccess 文件,以便我可以从我的网址中删除 index.php。但是,经过一番谷歌搜索后,我将这个线程上的答案和其他答案结合在一起。我的最终工作 .htaccess 文件具有以下内容:

    <IfModule mod_rewrite.c>
        # Turn on URL rewriting
        RewriteEngine On
    
        # If your website begins from a folder e.g localhost/my_project then 
        # you have to change it to: RewriteBase /my_project/
        # If your site begins from the root e.g. example.local/ then
        # let it as it is
        RewriteBase /
    
        # Protect application and system files from being viewed when the index.php is missing
        RewriteCond $1 ^(application|system|private|logs)
    
        # Rewrite to index.php/access_denied/URL
        RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
    
        # Allow these directories and files to be displayed directly:
        RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|app_upload|assets|css|js|images)
    
        # No rewriting
        RewriteRule ^(.*)$ - [PT,L]
    
        # Rewrite to index.php/URL
        RewriteRule ^(.*)$ index.php?/$1 [PT,L]
    </IfModule>
    

    【讨论】:

    • 这解决了我的问题,并让我的网站在 2021 年 10 月开始工作。谢谢!
    • 太棒了@WilfredAlmeida
    猜你喜欢
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    相关资源
    最近更新 更多