CodeIgniter:活服务器上找不到404页面

时间:2022-10-10 10:11:01

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应用程序。在本地测试之后,我把它放在我的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_html directory:

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

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

All of those are in the public_html directory. 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']。php,URL。同样的错误,当改变或留空时。我检查了我的路线,所有这些似乎都是正确的。在我的本地机器上导航到它时,所有东西都可以很好地加载。

I also am not using a .htaccess file at this time

我现在也不使用。htaccess文件

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

有什么建议吗?谢谢!

10 个解决方案

#1


78  

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'

你的控制器名是“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中,它可能不是强制的,但是在服务器中它会检查所有这些规则,否则它不能检测到正确的类名。

#2


15  

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

将文件名称和类名的首字母更改为大写字母是有效的。

file: controllers/Login.php

文件:控制器/ login

class: class Login extends CI_Controller { ... }

类:类登录扩展了CI_Controller{…}

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

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

https://ellislab.com/codeigniter/user-guide/general/models.html

https://ellislab.com/codeigniter/user-guide/general/models.html

#3


13  

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

我也有同样的问题。把第一个字母换成大写字母会有所帮助。

#4


11  

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-所有控制器类名都应该以大写字母开头。第一个字母应该是大写。我们有类名页的控制器

so it should be Pages not pages

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

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

2-将控制器类页面保存为页面。php不pages.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.php not page_model.php

同样,模型类的第一个字母应该是大写,并将模型类保存为Pages_model。php不page_model.php

hope this will solve ur problem

希望这能解决你的问题

#5


10  

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.

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

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

要测试这一点,创建一个“索引”。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.php and check your $config['base_url'] and $config['index_page'] screen shot below

2,检查你的配置/配置。php,检查你的$config['base_url']和$config['index_page']屏幕截图

CodeIgniter:活服务器上找不到404页面

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

我建议将站点名放在基本url示例“www.site.com/”中,但是删除索引。php进行清洗。

3, MOST LIKELY THE REASON SO START WITH THIS

原因很可能是这样的

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文件。这是我的,埃利奥特·豪顿做的。把它放在根目录中,如果需要,更改第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?/$1 [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.

如果以上方法都不奏效,那就回我一声,我们就能通过了。

#6


5  

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 / config . php

$config['base_url'] = '';

#7


3  

Solved the issue. Change your class name to make only the 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。将其应用于文件名和类名。

#8


2  

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

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


Routes:

路线:

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

Files' names:

文件的名字:

  • in controllers folder: Home_controller.php
  • 在控制器文件夹:Home_controller.php
  • in models folder: Home_model.php
  • 在模型中文件夹:Home_model.php
  • in views folder: Home.php
  • 在视图文件夹:home

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 :)

案例应该不会再有问题了

#9


0  

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

请检查根/应用程序/核心/文件夹文件是否使用了任何MY_Loader。php,MY_Parser。php或MY_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.

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

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

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

Hope that helps!

希望会有帮助!

#10


0  

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.

在应用程序/配置/配置。php第26行。

#1


78  

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'

你的控制器名是“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中,它可能不是强制的,但是在服务器中它会检查所有这些规则,否则它不能检测到正确的类名。

#2


15  

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

将文件名称和类名的首字母更改为大写字母是有效的。

file: controllers/Login.php

文件:控制器/ login

class: class Login extends CI_Controller { ... }

类:类登录扩展了CI_Controller{…}

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

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

https://ellislab.com/codeigniter/user-guide/general/models.html

https://ellislab.com/codeigniter/user-guide/general/models.html

#3


13  

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

我也有同样的问题。把第一个字母换成大写字母会有所帮助。

#4


11  

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-所有控制器类名都应该以大写字母开头。第一个字母应该是大写。我们有类名页的控制器

so it should be Pages not pages

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

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

2-将控制器类页面保存为页面。php不pages.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.php not page_model.php

同样,模型类的第一个字母应该是大写,并将模型类保存为Pages_model。php不page_model.php

hope this will solve ur problem

希望这能解决你的问题

#5


10  

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.

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

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

要测试这一点,创建一个“索引”。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.php and check your $config['base_url'] and $config['index_page'] screen shot below

2,检查你的配置/配置。php,检查你的$config['base_url']和$config['index_page']屏幕截图

CodeIgniter:活服务器上找不到404页面

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

我建议将站点名放在基本url示例“www.site.com/”中,但是删除索引。php进行清洗。

3, MOST LIKELY THE REASON SO START WITH THIS

原因很可能是这样的

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文件。这是我的,埃利奥特·豪顿做的。把它放在根目录中,如果需要,更改第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?/$1 [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.

如果以上方法都不奏效,那就回我一声,我们就能通过了。

#6


5  

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 / config . php

$config['base_url'] = '';

#7


3  

Solved the issue. Change your class name to make only the 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。将其应用于文件名和类名。

#8


2  

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

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


Routes:

路线:

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

Files' names:

文件的名字:

  • in controllers folder: Home_controller.php
  • 在控制器文件夹:Home_controller.php
  • in models folder: Home_model.php
  • 在模型中文件夹:Home_model.php
  • in views folder: Home.php
  • 在视图文件夹:home

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 :)

案例应该不会再有问题了

#9


0  

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

请检查根/应用程序/核心/文件夹文件是否使用了任何MY_Loader。php,MY_Parser。php或MY_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.

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

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

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

Hope that helps!

希望会有帮助!

#10


0  

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.

在应用程序/配置/配置。php第26行。