简体   繁体   English

在Live Server上找不到CodeIgniter:404页面

[英]CodeIgniter: 404 Page Not Found on Live Server

I have been developing a small web application with CodeIgniter. 我一直在使用CodeIgniter开发一个小型Web应用程序。 After testing it out locally I went to put it on my web server to allow a couple other people test out some features. 在本地对其进行测试之后,我将其放在Web服务器上,以允许其他几个人对某些功能进行测试。 While navigating to the site I get: - 导航到该网站时,我得到:-

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. 所有这些都在public_html目录中。 Like I said, it does give me CodeIgniters 404 error page, so I do know it is at least seeing CodeIgniter. 就像我说的,它确实给了我CodeIgniters 404错误页面,所以我确实知道至少看到了CodeIgniter。 I also tried changing the $config['base_url'] , in the config.php , to my URL. 我还尝试将config.php$config['base_url']更改为我的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. 在我的本地计算机上导航到所有内容时,一切也都可以正常加载。

I also am not using a .htaccess file at this time 我目前也没有使用.htaccess文件

Any suggestions on what I should try? 关于我应该尝试的任何建议?
Thanks a lot! 非常感谢!

You are using MVC with OOPS Concept. 您正在将MVC与OOPS概念一起使用。 So there are some certain rules. 因此,有一些特定的规则。

1) Your class name (ie: controller name) should be start with capital Letter. 1)您的班级名称(即控制器名称)应以大写字母开头。

eg: your controller name is 'icecream'. 例如:您的控制器名称为“ icecream”。 that should be ' I cecream' 那应该是“ cecream”

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

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

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,从本地主机(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". 只需按“ Ctrl + F ”并搜索“版本”。 You will find the php version. 您将找到php版本。 It may need to be 5.3+ to support features. 支持功能可能需要为5.3+。

2, Check your config/config.php and check your $config['base_url'] and $config['index_page'] screen shot below 2,检查您的config/config.php并检查下面的$config['base_url']$config['index_page'] 屏幕截图

在此处输入图片说明

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. 它很可能是.htaccess文件。 Here is mine Made by Elliot Haughton. 这是Elliot Haughton制造的。 Put this in your root directory and change line 9 'RewriteBase /' if necessary. 将其放在您的根目录中,并在必要时更改第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. 如果以上方法均无效,请给我回声,我们将逐步解决。

I had the same problem. 我有同样的问题。 Changing controlers first letter to uppercase helped. 将控件的首字母更改为大写会有所帮助。

I have solved this problem, please just make few changes 我已经解决了这个问题,请稍做更改

1- all controller class name should start with capital letter. 1-所有控制器类别名称应以大写字母开头。 i mean first letter of class should be capital . 我是说上课的第一个字母应该大写。 eg we have controler with class name Pages 例如我们有一个带有类名Pages的控件

so it should be Pages not pages 所以应该是页面而不是页面

2- save the controller class Pages as Pages.php not pages.php 2-将控制器类Pages保存为Pages.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 希望这能解决你的问题

I was stuck with this approx a day i just rename filename "Filename" with capital letter and rename the controller class "Classname". 我被困在大约一天的时间里,我只是用大写字母重命名文件名“ Filename”,然后重命名控制器类“ Classname”。 and it solved the problem. 它解决了问题。

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

application/config/config.php application / config / config.php

$config['base_url'] = '';

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'. 因此,如果您遇到类似“ MyClass”的内容,请将其更改为“ Myclass”。 apply it to both the file name and class name. 将其应用于文件名和类名。

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 controllers文件夹中: Home_controller.php
  • in models folder: Home_model.php models文件夹中: Home_model.php
  • in views folder: Home.php views文件夹中: 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 :) 案件应该不再有问题了:)

Try to add following line in root folder index.php after php starts: 尝试在php启动后在根文件夹index.php中添加以下行:

ob_start();

This works for me. 这对我有用。

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. 请检查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! 希望有帮助!

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行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM