简体   繁体   English

实时服务器显示404错误,但不在本地,codeigniter 3上

[英]live server shows 404 error, but not on local, codeigniter 3

I have four identical pages that only differs in some identifiers but the logic is very much the same. 我有四个相同的页面,只有一些标识符不同但逻辑非常相同。 All of them works on localhost. 所有这些都适用于localhost。 Three of those pages works okay on live server, but one of them returns a 404 for some reasons I can't understand. 其中三个页面在实时服务器上运行正常,但其中一个页面由于某些我无法理解的原因返回404。

I use XAMPP 3.2.2 and Sublime for developing it on local. 我使用XAMPP 3.2.2和Sublime在本地开发它。 I moved it to GoDaddy Deluxe Linux for live. 我把它移到了GoDaddy Deluxe Linux for live。 My Codeigniter version is 3.1.10. 我的Codeigniter版本是3.1.10。

I already tried answers from most of the questions on StackOverflow: 我已经尝试过StackOverflow上大多数问题的答案:

  1. All controller and model names' first letters are capitalized in the file name and inside the file. 所有控制器和型号名称的首字母都大写在文件名和文件内。

  2. All of the .htaccess codes on here: https://github.com/tasmanwebsolutions/htaccess_for_codeigniter 这里的所有.htaccess代码: https//github.com/tasmanwebsolutions/htaccess_for_codeigniter

  3. I have two .htaccess files, one of them is inside the application folder, and one is outside. 我有两个.htaccess文件,其中一个在应用程序文件夹中,一个在外面。 I don't know if that's confusing the system? 我不知道这是否令系统混乱? But I have another website on a different hosting that has the same .htaccess files and they're working okay. 但我有另一个网站在不同的主机上有相同的.htaccess文件,他们工作正常。 And anyway, if that's confusing the system, why does it only affect one of the four identical pages? 无论如何,如果这让系统混乱,为什么它只影响四个相同页面中的一个?

.htaccess outside application folder .htaccess外部应用程序文件夹

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

.htaccess inside application folder: 应用程序文件夹中的.htaccess:

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

All of the controllers of the four files has this up top: 这四个文件的所有控制器都有这个顶部:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//session_start(); //we need to call PHP's session object to access it through CI

class Question1 extends CI_Controller
{

and the rest is normal code stuff that are working on three of those four files. 其余的是正常的代码,正在处理这四个文件中的三个。

In config. 在配置中。 php I have: 我有:

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

and base_url is great. 和base_url很棒。

Models and views are okay, as far as I can see, and the rest of the website is functioning alright with the included .htaccess. 据我所知,模型和视图都可以,并且网站的其余部分正常运行,包括.htaccess。 My routes are working okay, as well. 我的路线工作正常。

I'm so lost right now. 我现在迷路了。

PS. PS。 I have a custom 404 page. 我有一个自定义的404页面。 When I input assessment.com/index.php/question1 it shows that custom 404 page. 当我输入assessment.com/index.php/question1时,它会显示自定义404页面。 But when I open assessment.com/question1 it shows codeigniter's own 404 page (and not my custom one, for some reasons). 但是,当我打开assessment.com/question1时,它会显示codeigniter自己的404页面(而不是我的自定义页面,出于某些原因)。 I think that tells something, I just don't know what. 我认为这说了些什么,我只是不知道是什么。

EDIT 编辑

Here's my routes.php: 这是我的routes.php:

$route['default_controller'] = 'home';
$route['404_override'] = 'Error404';
$route['translate_uri_dashes'] = TRUE;

I opted not to do $route['question1'] = "Question1"; 我选择不做$ route ['question1'] =“Question1”; in routes because it doesn't change anything. 在路线中,因为它不会改变任何东西。

Check your APPLICATION ENVIRONMENT mode. 检查您的应用环境模式。 You can find it on your project root_folder/index.php and at line no. 您可以在项目root_folder / index.php和第no行找到它。 57. 57。

define('ENVIRONMENT', 'production');

Change the ENVIRONMENT mode into the development mode, that is 将环境模式更改为开发模式,即

define('ENVIRONMENT', 'development');

Then refresh your applications again. 然后再次刷新您的应用程序 If you see CodeIgniter default error you can understand your CodeIgniter application are running ok and check out the error.If it doesn't show any error then your .httaccess has any error. 如果您看到CodeIgniter默认错误,您可以理解您的CodeIgniter应用程序运行正常并检查错误。如果它没有显示任何错误,那么您的.httaccess有任何错误。 I solved it my 404 error with this code, you can check this out. 我用这段代码解决了我的404错误,你可以查看一下。

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^asset.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Answering this for the others who might come across the same problem. 为可能遇到同样问题的其他人回答这个问题。

Okay so user Don't Panic suggested I echo just "question x" in the problematic controller, and when I did that, the 404 error went away and it echoed the "question x." 好吧所以用户不要恐慌建议我在有问题的控制器中只回显“问题x”,当我这样做时,404错误就消失了,它回应了“问题x”。 So definitely it's my controller that has the problem and not my routine or .htaccess files. 所以肯定是我的控制器有问题而不是我的例程或.htaccess文件。

Now this controller is designed in such a way that it calls first an ID from the database before it shows anything. 现在,这个控制器的设计使它在显示任何内容之前首先从数据库中调用一个ID。 After I echoed "question x" I realized that the ID it is calling from my database has a value of zero. 在我回答“问题x”后,我意识到它从我的数据库调用的ID的值为零。 So, unsurprisingly, from the controller's point of view, the page doesn't exist! 所以,不出所料,从控制器的角度来看,页面不存在! Hence the 404. 因此404。

I've fixed it now by updating that table from my database and giving the ID a value it should already have had in the first place. 我现在通过从我的数据库中更新该表并为ID提供一个它应该已经拥有的值来修复它。

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

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