CodeIgniter 404找不到页面,但为什么?

时间:2022-10-10 08:01:33

I am using CodeIgniter for two applications (a public and an admin app). The important elements of the document structure are:

我正在为两个应用程序(公共和管理员应用程序)使用CodeIgniter。文档结构的重要元素是:

/admin
/admin/.htaccess
/admin/index.html
/application
/application/admin
/application/public
/system
.htaccess
index.php

The /admin/.htaccess file looks like this:

/admin/.htaccess文件如下所示:

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

The /admin/index.php has the following changes:

/admin/index.php有以下更改:

$system_folder = "../system";
$application_folder = "../application/admin"; (this line exists of course twice)

And the /application/admin/config/routes.php contains the following:

/application/admin/config/routes.php包含以下内容:

$route['default_controller'] = "welcome";
$route['admin'] = 'welcome';

Welcome is my default controller.

欢迎是我的默认控制器。

When I call up the Domain/admin I get a 404 Page Not Found error. When I call up the Domain/admin/welcome everything works fine. In the debug logs I get the following error message:

当我调用域/管理员时,我收到404 Page Not Found错误。当我调用Domain / admin / welcome时,一切正常。在调试日志中,我收到以下错误消息:

DEBUG - 2010-09-20 16:27:34 --> Config Class Initialized
DEBUG - 2010-09-20 16:27:34 --> Hooks Class Initialized
DEBUG - 2010-09-20 16:27:34 --> URI Class Initialized
ERROR - 2010-09-20 16:27:34 --> 404 Page Not Found --> admin

Weirdly enough this setup works perfectly on my local MAMP installation (with the localdomain/admin/), but when I publish and test it on the "live" server, I just get 404 errors.

奇怪的是,这个设置完全适用于我的本地MAMP安装(使用localdomain / admin /),但是当我在“实时”服务器上发布并测试它时,我只得到404错误。

Any ideas? What am I doing wrong? Thanks C.

有任何想法吗?我究竟做错了什么?谢谢C.

9 个解决方案

#1


16  

The cause of the problem was that the server was running PHP using FastCGI.

问题的原因是服务器使用FastCGI运行PHP。

After changing the config.php to

将config.php更改为

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

everything worked.

一切顺利。

#2


6  

Leaving this answer here for others who ran into my situation.

将此答案留给了遇到我情况的其他人。

My codeigniter app was working fine in localhost/WAMP, but was unable to route and produced 404 not found errors when pushing to an AWS EC2 instance. My issue was solved from the answer from HERE htaccess works in localhost but doesn't work in EC2 instance

我的codeigniter应用程序在localhost / WAMP中工作正常,但在推送到AWS EC2实例时无法路由并产生404未找到的错误。我的问题是从HERE htaccess在localhost中的答案解决的,但在EC2实例中不起作用

(route to my admin page) {domain}/admin was producing 404

(路由到我的管理页面){domain} / admin正在生成404

the /etc/httpd/conf/httpd.conf file needs to be modified.

需要修改/etc/httpd/conf/httpd.conf文件。

-after every instance of "DocumentRoot "/var/www/html"" (2 places) "AllowOverride None" needed to be changed to "AllowOverride All".

- 在“DocumentRoot”/ var / www / html“”(2个地方)的每个实例之后,需要将“AllowOverride None”更改为“AllowOverride All”。

Restarted the EC2 instance from the AWS dashboard.

从AWS仪表板重新启动EC2实例。

{domain}/admin is now accessible and working as intended.

{domain} / admin现在可以访问并按预期工作。

hope this helps someone else like it helped me!

希望这有助于其他人喜欢它帮助我!

#3


3  

You could try one of two things or a combination of both.

您可以尝试两种方法中的一种或两种方式的组合。

  1. Be sure that your controller's name starts with a capital letter. eg "Mycontroller.php"
  2. 确保您的控制器名称以大写字母开头。例如“Mycontroller.php”
  3. If you have not made any changes to your route, for some strange reason, you might have to include capital letters in your url. e.g if your controller is 'Mycontroller.php' with a function named 'testfunc' inside it, then your url will look like this: "http://www.yourdomain/index.php/Mycontroller/testfunc". Note the capital letter. (I'm assuming you haven't added the htaccess file to remove the 'index.php' part. If you have, just remove it from the url.)
  4. 如果您没有对路线进行任何更改,由于某些奇怪的原因,您可能必须在您的网址中包含大写字母。例如,如果您的控制器是“Mycontroller.php”,其中包含一个名为“testfunc”的函数,那么您的网址将如下所示:“http://www.yourdomain/index.php/Mycontroller/testfunc”。注意大写字母。 (我假设您没有添加htaccess文件来删除'index.php'部分。如果有,请将其从网址中删除。)

I hope this helps someone

我希望这可以帮助别人

#4


1  

Your folder/file structure seems a little odd to me. I can't quite figure out how you've got this laid out.

你的文件夹/文件结构对我来说有点奇怪。我无法弄清楚你是如何制定这个的。

Hello I am using CodeIgniter for two applications (a public and an admin app).

您好我正在为两个应用程序(公共和管理应用程序)使用CodeIgniter。

This sounds to me like you've got two separate CI installations. If this is the case, I'd recommend against it. Why not just handle all admin stuff in an admin controller? If you do want two separate CI installations, make sure they are definitely distinct entities and that the two aren't conflicting with one another. This line:

这听起来像你有两个单独的CI安装。如果是这种情况,我建议不要这样做。为什么不在管理控制器中处理所有管理员的东西呢?如果您确实需要两个单独的CI安装,请确保它们绝对是不同的实体,并且两者不会相互冲突。这一行:

$system_folder = "../system";
$application_folder = "../application/admin"; (this line exists of course twice)

And the place you said this exists (/admin/index.php...or did you mean /admin/application/config?) has me scratching my head. You have admin/application/admin and a system folder at the top level?

你说这个存在的地方(/admin/index.php ...或你的意思是/ admin / application / config?)让我摸不着头脑。你有管理员/应用程序/管理员和*系统文件夹?

#5


1  

we have to give the controller name in lower cases in server side

我们必须在服务器端以较小的情况给出控制器名称

$this->class = strtolower(__CLASS__);

#6


1  

I had the same issue after migrating to a new environment and it was simply that the server didn't run mod_rewrite

迁移到新环境后我遇到了同样的问题,只是服务器没有运行mod_rewrite

a quick sudo a2enmod rewrite then sudo systemctl restart apache2

快速sudo a2enmod重写然后sudo systemctl重启apache2

and problem solved...

问题解决了......

Thanks @fanis who pointed that out in his comment on the question.

谢谢@fanis在他对这个问题的评论中指出了这一点。

#7


0  

In my case I was using it on localhost and forgot to change RewriteBase in .htaccess.

在我的情况下,我在localhost上使用它,忘了在.htaccess中更改RewriteBase。

#8


0  

  1. Change your controller name first letter to uppercase.
  2. 将控制器名称首字母更改为大写。
  3. Change your url same as your controller name.
  4. 更改与控制器名称相同的URL。

e.g:

例如:

Your controller name is YourController

您的控制器名称是YourController

Your url must be:

你的网址必须是:

http://example.com/index.php/YourController/method

http://example.com/index.php/YourController/method

Not be:

不是:

http://example.com/index.php/yourcontroller/method

http://example.com/index.php/yourcontroller/method

#9


-2  

Check Your Directory Find Any Space Codignater MAny Times Give Error When You Space In Your Directory Of Codignater Remove All Space From Directory Example

检查您的目录查找任何空间Codignater在您的Codignater目录中留出空间时出现错误从目录示例中删除所有空间

ITWORLD compk

change it To

改变它

ITWORLD_COM_PK

#1


16  

The cause of the problem was that the server was running PHP using FastCGI.

问题的原因是服务器使用FastCGI运行PHP。

After changing the config.php to

将config.php更改为

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

everything worked.

一切顺利。

#2


6  

Leaving this answer here for others who ran into my situation.

将此答案留给了遇到我情况的其他人。

My codeigniter app was working fine in localhost/WAMP, but was unable to route and produced 404 not found errors when pushing to an AWS EC2 instance. My issue was solved from the answer from HERE htaccess works in localhost but doesn't work in EC2 instance

我的codeigniter应用程序在localhost / WAMP中工作正常,但在推送到AWS EC2实例时无法路由并产生404未找到的错误。我的问题是从HERE htaccess在localhost中的答案解决的,但在EC2实例中不起作用

(route to my admin page) {domain}/admin was producing 404

(路由到我的管理页面){domain} / admin正在生成404

the /etc/httpd/conf/httpd.conf file needs to be modified.

需要修改/etc/httpd/conf/httpd.conf文件。

-after every instance of "DocumentRoot "/var/www/html"" (2 places) "AllowOverride None" needed to be changed to "AllowOverride All".

- 在“DocumentRoot”/ var / www / html“”(2个地方)的每个实例之后,需要将“AllowOverride None”更改为“AllowOverride All”。

Restarted the EC2 instance from the AWS dashboard.

从AWS仪表板重新启动EC2实例。

{domain}/admin is now accessible and working as intended.

{domain} / admin现在可以访问并按预期工作。

hope this helps someone else like it helped me!

希望这有助于其他人喜欢它帮助我!

#3


3  

You could try one of two things or a combination of both.

您可以尝试两种方法中的一种或两种方式的组合。

  1. Be sure that your controller's name starts with a capital letter. eg "Mycontroller.php"
  2. 确保您的控制器名称以大写字母开头。例如“Mycontroller.php”
  3. If you have not made any changes to your route, for some strange reason, you might have to include capital letters in your url. e.g if your controller is 'Mycontroller.php' with a function named 'testfunc' inside it, then your url will look like this: "http://www.yourdomain/index.php/Mycontroller/testfunc". Note the capital letter. (I'm assuming you haven't added the htaccess file to remove the 'index.php' part. If you have, just remove it from the url.)
  4. 如果您没有对路线进行任何更改,由于某些奇怪的原因,您可能必须在您的网址中包含大写字母。例如,如果您的控制器是“Mycontroller.php”,其中包含一个名为“testfunc”的函数,那么您的网址将如下所示:“http://www.yourdomain/index.php/Mycontroller/testfunc”。注意大写字母。 (我假设您没有添加htaccess文件来删除'index.php'部分。如果有,请将其从网址中删除。)

I hope this helps someone

我希望这可以帮助别人

#4


1  

Your folder/file structure seems a little odd to me. I can't quite figure out how you've got this laid out.

你的文件夹/文件结构对我来说有点奇怪。我无法弄清楚你是如何制定这个的。

Hello I am using CodeIgniter for two applications (a public and an admin app).

您好我正在为两个应用程序(公共和管理应用程序)使用CodeIgniter。

This sounds to me like you've got two separate CI installations. If this is the case, I'd recommend against it. Why not just handle all admin stuff in an admin controller? If you do want two separate CI installations, make sure they are definitely distinct entities and that the two aren't conflicting with one another. This line:

这听起来像你有两个单独的CI安装。如果是这种情况,我建议不要这样做。为什么不在管理控制器中处理所有管理员的东西呢?如果您确实需要两个单独的CI安装,请确保它们绝对是不同的实体,并且两者不会相互冲突。这一行:

$system_folder = "../system";
$application_folder = "../application/admin"; (this line exists of course twice)

And the place you said this exists (/admin/index.php...or did you mean /admin/application/config?) has me scratching my head. You have admin/application/admin and a system folder at the top level?

你说这个存在的地方(/admin/index.php ...或你的意思是/ admin / application / config?)让我摸不着头脑。你有管理员/应用程序/管理员和*系统文件夹?

#5


1  

we have to give the controller name in lower cases in server side

我们必须在服务器端以较小的情况给出控制器名称

$this->class = strtolower(__CLASS__);

#6


1  

I had the same issue after migrating to a new environment and it was simply that the server didn't run mod_rewrite

迁移到新环境后我遇到了同样的问题,只是服务器没有运行mod_rewrite

a quick sudo a2enmod rewrite then sudo systemctl restart apache2

快速sudo a2enmod重写然后sudo systemctl重启apache2

and problem solved...

问题解决了......

Thanks @fanis who pointed that out in his comment on the question.

谢谢@fanis在他对这个问题的评论中指出了这一点。

#7


0  

In my case I was using it on localhost and forgot to change RewriteBase in .htaccess.

在我的情况下,我在localhost上使用它,忘了在.htaccess中更改RewriteBase。

#8


0  

  1. Change your controller name first letter to uppercase.
  2. 将控制器名称首字母更改为大写。
  3. Change your url same as your controller name.
  4. 更改与控制器名称相同的URL。

e.g:

例如:

Your controller name is YourController

您的控制器名称是YourController

Your url must be:

你的网址必须是:

http://example.com/index.php/YourController/method

http://example.com/index.php/YourController/method

Not be:

不是:

http://example.com/index.php/yourcontroller/method

http://example.com/index.php/yourcontroller/method

#9


-2  

Check Your Directory Find Any Space Codignater MAny Times Give Error When You Space In Your Directory Of Codignater Remove All Space From Directory Example

检查您的目录查找任何空间Codignater在您的Codignater目录中留出空间时出现错误从目录示例中删除所有空间

ITWORLD compk

change it To

改变它

ITWORLD_COM_PK