php CodeIgniter:在实时服务器上找不到 404 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28709185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:01:06  来源:igfitidea点击:

CodeIgniter: 404 Page Not Found on Live Server

phpcodeigniter

提问by twigman08

I have been developing a small web application with CodeIgniter. After testing it out locally I went to put it on my web server to allow a couple other people test out some features. While navigating to the site I get: -

我一直在使用 CodeIgniter 开发一个小型 Web 应用程序。在本地测试之后,我将它放在我的网络服务器上,让其他几个人测试一些功能。在导航到该网站时,我得到:-

404 Page Not Found error page

404页面未找到错误页面

When viewing it in my local machine everything loads up and runs perfectly.

在我的本地机器上查看它时,一切都加载并完美运行。

This is what I uploaded to the public_htmldirectory:

这是我上传到public_html目录的内容:

application directory
system directory
assets directory (my assets for the site)
index.php

All of those are in the public_htmldirectory. Like I said, it does give me CodeIgniters 404 error page, so I do know it is at least seeing CodeIgniter. I also tried changing the $config['base_url'], in the config.php, to my URL. Same error when changing that or leaving it blank. I checked my routes, and all those seem correct. Everything also loads up just fine when navigating to it on my local machine.

所有这些都在public_html目录中。就像我说的,它确实给了我 CodeIgniters 404 错误页面,所以我知道它至少看到了 CodeIgniter。我还尝试将$config['base_url'], 中的更改config.php为我的 URL。更改它或将其留空时出现相同的错误。我检查了我的路线,所有这些似乎都是正确的。在我的本地机器上导航到它时,一切也都加载得很好。

I also am not using a .htaccessfile at this time

我此时也没有使用.htaccess文件

Any suggestions on what I should try?
Thanks a lot!

关于我应该尝试什么的任何建议?
非常感谢!

回答by Binoj T E

You are using MVC with OOPS Concept. So there are some certain rules.

您正在使用带有 OOPS 概念的 MVC。所以有一些特定的规则。

1) Your class name (ie: controller name) should be start with capital Letter.

1)您的类名(即:控制器名称)应以大写字母开头。

e.g.: your controller name is 'icecream'. that should be 'Icecream'

例如:您的控制器名称是“冰淇淋”。那应该是'冰淇淋'

In localhost it might not be compulsory, but in server it will check all these rules, else it can't detect the right class name.

在 localhost 中它可能不是强制性的,但在服务器中它会检查所有这些规则,否则它无法检测到正确的类名。

回答by PolloZen

Changing the first letter to uppercase on the file's name and class name works.

将文件名和类名的第一个字母更改为大写。

file:controllers/Login.php

文件:controllers/Login.php

class:class Login extends CI_Controller { ... }

班级:class Login extends CI_Controller { ... }

The file name, as the class name, should starts with capital letter. This rule applys to models too.

文件名作为类名,应以大写字母开头。此规则也适用于模型。

https://www.codeigniter.com/user_guide/general/models.html

https://www.codeigniter.com/user_guide/general/models.html

回答by Mantas Andriu?ka

I had the same problem. Changing controlers first letter to uppercase helped.

我有同样的问题。将控制器的第一个字母更改为大写有帮助。

回答by Niall Lonergan

There are a number of things you can check here. I'll go over each one with you.

您可以在此处查看许多内容。我会和你逐一讨论。

1,When moving to a live server from localhost(htdocs) you need to make sure that the version of PHP you are using is supported.

1、当从 localhost(htdocs) 移动到实时服务器时,您需要确保支持您使用的 PHP 版本。

To test this: Create an 'index.php' file and add the below line only.

要对此进行测试:创建一个“ index.php”文件并仅添加以下行。

<?php phpinfo(); ?>

Just press 'Ctrl + F' and search "version". You will find the php version. It may need to be 5.3+ to support features.

只需按“ Ctrl + F”并搜索“版本”。您将找到 php 版本。可能需要 5.3+ 才能支持功能。

2,Check your config/config.phpand check your $config['base_url']and $config['index_page']screen shot below

2,检查你的config/config.php和检查你的$config['base_url']$config['index_page']下面的屏幕截图

enter image description here

在此处输入图片说明

I recommend putting site name in the base url example: 'www.site.com/' but remove the index.php for cleaning.

我建议将站点名称放在基本 url 示例中:' www.site.com/' 但删除 index.php 以进行清理。

3,MOST LIKELY THE REASON SO START WITH THIS

3,很可能是从这个开始的原因

It most likely is the .htaccess file. Here is mine Made by Elliot Haughton. Put this in your root directory and change line 9 'RewriteBase /' if necessary.

它很可能是 .htaccess 文件。这是我的,由 Elliot Haughton 制作。将其放在根目录中,如有必要,请更改第 9 行“RewriteBase /”。

<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin 
ErrorDocument 404 /index.php

(Make sure you use both parts above. The editor broke it in two but all code above is one .htaccess file).

(确保你使用了上面的两个部分。编辑器把它分成两部分,但上面的所有代码都是一个 .htaccess 文件)。

If none of the above works, give me a shout back and we'll step through it.

如果以上方法都不奏效,请回复我,我们将逐步完成。

回答by Mian Ajmal

I have solved this problem, please just make few changes

我已经解决了这个问题,请做一些更改

1- all controller class name should start with capital letter. i mean first letter of class should be capital . eg we have controler with class name Pages

1- 所有控制器类名称都应以大写字母开头。我的意思是类的第一个字母应该是大写的。例如,我们有类名为 Pages 的控制器

so it should be Pages not pages

所以它应该是页面而不是页面

2- save the controller class Pages as Pages.phpnot pages.php

2- 将控制器类 Pages 保存为 Pages.phpnotpages.php

so first letter must be capital

所以第一个字母必须是大写

same for model, model class first letter should be capital and also save model class as Pages_model.phpnot page_model.php

模型相同,模型类首字母应大写,并将模型类另存为 Pages_model.phppage_model.php

hope this will solve ur problem

希望这能解决你的问题

回答by Ahmad Sayeed

I was stuck with this approx a day i just rename filename "Filename" with capital letter and rename the controller class "Classname". and it solved the problem.

我被这个问题困扰了大约一天,我只是用大写字母重命名文件名“Filename”并重命名控制器类“Classname”。它解决了这个问题。

**class Myclass extends CI_Controller{}
save file: Myclass.php**

application/config/config.php

应用程序/配置/config.php

$config['base_url'] = '';

回答by Sheychan

Solved the issue. Change your class name to make onlythe first letter capitalized. so if you got something like 'MyClass' change it to 'Myclass'. apply it to both the file name and class name.

解决了这个问题。更改您的班级名称以将第一个字母大写。所以如果你有像“MyClass”这样的东西,把它改成“Myclass”。将其应用于文件名和类名。

回答by Sid

I am doing it on local and production server this way:

我在本地和生产服务器上这样做:



Routes:

路线:

$route['default_controller']   = 'Home_controller';


Files' names:

文件名:

  • in controllersfolder: Home_controller.php
  • in modelsfolder: Home_model.php
  • in viewsfolder: Home.php
  • 控制器文件夹中:Home_controller.php
  • 模型文件夹中:Home_model.php
  • 视图文件夹中:Home.php


Home_controller.php:

Home_controller.php:

       class Home_controller extends CI_Controller {

           public function index(){

              //loading Home_model
              $this->load->model('Home_model');

              //get data from DB
              $data['db_data']  = $this->Home_model->getData();

              //pass $data to Home.html
              $this->load->view('Home', $data);
           }
       }


Home_model.php:

Home_model.php:

       class Home_model extends CI_Model {
       ...
       }


There should be no more problems with cases anymore :)

案例应该不会再有问题了:)

回答by rc.adhikari

Please check the root/application/core/folder files whether if you have used any of MY_Loader.php, MY_Parser.phpor MY_Router.phpfiles.

请检查root/application/core/文件夹文件是否使用过MY_Loader.phpMY_Parser.phpMY_Router.php文件中的任何一个。

If so, please try by removing above files from the folder and check whether that make any difference. In fact, just clean that folder by just keeping the default index.html file.

如果是这样,请尝试从文件夹中删除上述文件并检查是否有任何区别。实际上,只需保留默认的 index.html 文件即可清理该文件夹。

I have found these files caused the issue to route to the correct Controller's functions.

我发现这些文件导致问题路由到正确的控制器功能。

Hope that helps!

希望有帮助!

回答by Greg Vazquez

I was able to fix similar errors by changeing

我能够通过更改来修复类似的错误

http://ip-address/html/ci3-fire-starter/htdocs/index.php/

on the application/config/config.php line 26.

在 application/config/config.php 第 26 行。