使用路由和“索引”控制器在Kohana 2.3.4(2.4)中发布

时间:2022-01-26 07:06:27

I have: brand new clean copy of Kohana 2.3.4 (tried 2.4 RC1 also), a controller named 'index' on a Debian with Apache 2.2.9.

我有:全新的Kohana 2.3.4副本(也试过2.4 RC1),一个名为'index'的控制器在Debian上使用Apache 2.2.9。

When i type address like http://localhost/kohana/index/index i expect controller 'index', action 'index' to be executed. It works on Windows localhost, works on shared hosting. But does not on my Debian server.

当我输入像http:// localhost / kohana / index / index这样的地址时,我希望控制器'索引',动作'索引'被执行。它适用于Windows localhost,适用于共享主机。但是我的Debian服务器上没有。

I've debugged and found, that $_SERVER['PATH_INFO'] isn't correct. It omits the first 'index' in the URI, so i can get to 'index/index' by going to 'index/index/index'. So that is what i want to fix.

我调试并发现$ _SERVER ['PATH_INFO']不正确。它省略了URI中的第一个'索引',所以我可以通过转到'index / index / index'来获得'index / index'。这就是我想要解决的问题。

Does anybody know how this could be solved?

有谁知道如何解决这个问题?

2 个解决方案

#1


0  

I'm guessing it actually occurs in your .htaccess file or Apache config, not Kohana specifically. First of all, make sure that the example.htaccess file that comes with Kohana is renamed to .htaccess, and you may have to restart Apache.

我猜它实际上发生在你的.htaccess文件或Apache配置中,而不是Kohana。首先,确保将Kohana附带的example.htaccess文件重命名为.htaccess,并且可能必须重新启动Apache。

If you are using .htaccess to hide the index.php part of the path, check to see what the RewriteBase setting is:

如果您使用.htaccess隐藏路径的index.php部分,请检查RewriteBase设置是什么:

RewriteBase /kohana/

If you installed it in the root of your web server (as in production, or using a separate port for localhost), then it should be changed to:

如果您将其安装在Web服务器的根目录中(如生产中,或使用localhost的单独端口),则应将其更改为:

RewriteBase /

This is my own personal most common error in setting up new sites and development environments, by the way. This is also true for CodeIgniter and other related PHP frameworks.

顺便提一下,这是我在设置新站点和开发环境时最常见的个人错误。对于CodeIgniter和其他相关的PHP框架也是如此。

Does your Apache install on the Debian server actually have mod_rewrite? It would be good to confirm that. Here's one way to do that.

您在Debian服务器上安装的Apache实际上是否有mod_rewrite?确认这一点会很好。这是一种方法。

Further diagnosis to see if it is Kohana or Apache's fault includes adding back in the index.php portion of the path. In your case, try http://localhost/kohana/index.php/index. Finally, I have to agree with sarfraz above that naming your controller "index" is just begging for trouble. My own convention is to call it "home" and to edit the default route accordingly.

进一步诊断以确定它是Kohana还是Apache的错误包括在路径的index.php部分中添加回来。在您的情况下,请尝试http://localhost/kohana/index.php/index。最后,我必须同意上面的sarfraz,命名你的控制器“索引”只是乞求麻烦。我自己的惯例是将其称为“home”并相应地编辑默认路由。

#2


0  

It turned out to be mod_negotitaion. It damn mod rewrites my /index/index to /index.php/index, cause it thought i've missed .php

原来是mod_negotitaion。该死的mod将我的/ index / index重写为/index.php/index,因为它认为我错过了.php

So anyone who encounter this issue, just disable mod_negotiation and have a good time

所以遇到这个问题的人,只需禁用mod_negotiation并享受愉快的时光

#1


0  

I'm guessing it actually occurs in your .htaccess file or Apache config, not Kohana specifically. First of all, make sure that the example.htaccess file that comes with Kohana is renamed to .htaccess, and you may have to restart Apache.

我猜它实际上发生在你的.htaccess文件或Apache配置中,而不是Kohana。首先,确保将Kohana附带的example.htaccess文件重命名为.htaccess,并且可能必须重新启动Apache。

If you are using .htaccess to hide the index.php part of the path, check to see what the RewriteBase setting is:

如果您使用.htaccess隐藏路径的index.php部分,请检查RewriteBase设置是什么:

RewriteBase /kohana/

If you installed it in the root of your web server (as in production, or using a separate port for localhost), then it should be changed to:

如果您将其安装在Web服务器的根目录中(如生产中,或使用localhost的单独端口),则应将其更改为:

RewriteBase /

This is my own personal most common error in setting up new sites and development environments, by the way. This is also true for CodeIgniter and other related PHP frameworks.

顺便提一下,这是我在设置新站点和开发环境时最常见的个人错误。对于CodeIgniter和其他相关的PHP框架也是如此。

Does your Apache install on the Debian server actually have mod_rewrite? It would be good to confirm that. Here's one way to do that.

您在Debian服务器上安装的Apache实际上是否有mod_rewrite?确认这一点会很好。这是一种方法。

Further diagnosis to see if it is Kohana or Apache's fault includes adding back in the index.php portion of the path. In your case, try http://localhost/kohana/index.php/index. Finally, I have to agree with sarfraz above that naming your controller "index" is just begging for trouble. My own convention is to call it "home" and to edit the default route accordingly.

进一步诊断以确定它是Kohana还是Apache的错误包括在路径的index.php部分中添加回来。在您的情况下,请尝试http://localhost/kohana/index.php/index。最后,我必须同意上面的sarfraz,命名你的控制器“索引”只是乞求麻烦。我自己的惯例是将其称为“home”并相应地编辑默认路由。

#2


0  

It turned out to be mod_negotitaion. It damn mod rewrites my /index/index to /index.php/index, cause it thought i've missed .php

原来是mod_negotitaion。该死的mod将我的/ index / index重写为/index.php/index,因为它认为我错过了.php

So anyone who encounter this issue, just disable mod_negotiation and have a good time

所以遇到这个问题的人,只需禁用mod_negotiation并享受愉快的时光