I'm developing a website using Kohana 3 (1rst time I use a framework). Locally, everything works perfectly. At the moment, I have a default template controller, a multi-language support and my 'index.php' is correctly removed. So before going further, I tested if it worked on my server and I got an endless loop.
我正在使用Kohana 3开发一个网站(我第一次使用框架)。在当地,一切都很完美。目前,我有一个默认的模板控制器,一个多语言支持,我的'index.php'被正确删除。所以在进一步研究之前,我测试了它是否在我的服务器上工作,并且我得到了无限循环。
I followed the tutorial from the unofficial wiki for the multi-language implementation: http://www.kerkness.ca/wiki/doku.php?id=example_of_a_multi-language_website
我按照非官方wiki的教程进行了多语言实现:http://www.kerkness.ca/wiki/doku.php?id = example_of_a_multi-language_website
A redirection to the default language occurs if the language is not specified in the uri so I figured the problem might have come from there even though it worked locally, so I removed it to see what happens without the redirection. Now, I can see my home page, but whatever the uri is in the web browser, the home page will always be called. I inserted the following line in my home view to check what the uri was: request::instance()->uri() and effectively, the uri is always: /en/home/
如果未在uri中指定语言,则会重定向到默认语言,所以我认为问题可能来自那里,即使它在本地工作,所以我删除它以查看没有重定向会发生什么。现在,我可以看到我的主页,但无论网页浏览器中的uri是什么,都会始终调用主页。我在我的主视图中插入以下行来检查uri是什么:request :: instance() - > uri()并且有效地,uri总是:/ en / home /
I put the index.php back (in the bootstrap) and everything worked fine again, even with the redirection to the default language.
我将index.php放回(在引导程序中)并且一切正常,即使重定向到默认语言也是如此。
My first guess was that the uri isn't rewritten correctly, so I tried to change the .htaccess but no success...
我的第一个猜测是uri没有被正确重写,所以我试图改变.htaccess但没有成功......
Here's my .htaccess:
这是我的.htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /dev/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)/ - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
(btw I also tried the other RewriteRule in the unofficial wiki, doesn't work either)
(顺便说一句,我也尝试过非官方wiki中的其他RewriteRule,也不起作用)
Additional info: Host: WebHostingPad Apache: v2.2.11 PHP: 5.2.9
附加信息:主机:WebHostingPad Apache:v2.2.11 PHP:5.2.9
Rewrite_Module is activated
Rewrite_Module已激活
Thank you, I would really appreciate your help because I've been trying to fix this for days now and it's really starting to annoy me ;)
谢谢,我真的很感谢你的帮助,因为我一直试图解决这个问题已经好几天了,它真的开始惹恼我了;)
2 个解决方案
#1
3
The only thing you have to change in order to get rid of index.php in URL is to set the 'index_file' param in Kohana::init ( bootstrap.php ) to FALSE ( everything else can cause an error ).
为了摆脱URL中的index.php,你唯一需要改变的是将Kohana :: init(bootstrap.php)中的'index_file'参数设置为FALSE(其他一切都可能导致错误)。
So the Kohana::init looks like this;
所以Kohana :: init看起来像这样;
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
));
If it worked with the original .htaccess, there's no need to change it at all.
如果它与原始.htaccess一起工作,则根本不需要改变它。
#2
1
The problem came from $_SERVER['PATH_INFO']
which returned no value...
问题来自$ _SERVER ['PATH_INFO'],它没有返回任何值......
This issue can be solved by adding the following line to the php.ini:
这个问题可以通过在php.ini中添加以下行来解决:
cgi.fix_pathinfo=0
#1
3
The only thing you have to change in order to get rid of index.php in URL is to set the 'index_file' param in Kohana::init ( bootstrap.php ) to FALSE ( everything else can cause an error ).
为了摆脱URL中的index.php,你唯一需要改变的是将Kohana :: init(bootstrap.php)中的'index_file'参数设置为FALSE(其他一切都可能导致错误)。
So the Kohana::init looks like this;
所以Kohana :: init看起来像这样;
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
));
If it worked with the original .htaccess, there's no need to change it at all.
如果它与原始.htaccess一起工作,则根本不需要改变它。
#2
1
The problem came from $_SERVER['PATH_INFO']
which returned no value...
问题来自$ _SERVER ['PATH_INFO'],它没有返回任何值......
This issue can be solved by adding the following line to the php.ini:
这个问题可以通过在php.ini中添加以下行来解决:
cgi.fix_pathinfo=0