如何正确设置 Kohana 的 .htaccess,以便 URL 中没有丑陋的“index.php/”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/966429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set up .htaccess for Kohana correctly, so that there is no ugly "index.php/" in the URL?
提问by Thanks
After 2 hours now I couldn't get it right.
现在 2 小时后,我无法做对。
The Kohana installation is accessible directly under my domain, i.e. "http://something.org/"
Kohana 安装可以直接在我的域下访问,即“ http://something.org/”
Instead of http://something.org/index.php/welcomde/indexI want to have URLs like http://something.org/welcome/index
而不是http://something.org/index.php/welcomde/index我想要像http://something.org/welcome/index这样的 URL
My .htaccess is messed up completely. It's actually the standard example.htaccess that came with the download. It's almost useless. On the kohana page is a tutorial "how to remove the index.php". It's really useless as well, since it will not even talk about how to remove it. Totally confusing.
我的 .htaccess 完全搞砸了。它实际上是下载附带的标准 example.htaccess。几乎没用。在 kohana 页面上有一个教程“如何删除 index.php”。它也真的没用,因为它甚至不会谈论如何删除它。完全混乱。
Please, can someone provide his working .htaccess for a standard kohana installation?
请问,有人可以为标准的kohana安装提供他的工作.htaccess吗?
回答by Ambirex
My htaccess looks like the example.
我的 htaccess 看起来像这个例子。
RewriteEngine On
RewriteBase /
RewriteRule ^(application|modules|system) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$config['index_page'] = '';
[PT,L]
But you also have to change the config.phpfile to:
但是您还必须将config.php文件更改为:
RewriteEngine On
# 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/RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php index.php%{REQUEST_URI} [L]
[PT,L]
回答by davidtbernal
This is our .htaccess file right now, and it seems to be working.
这是我们现在的 .htaccess 文件,它似乎正在工作。
public static function site($uri = '', $protocol = NULL, $index = TRUE)
Note that we have our application, system and modules directories all outside of the web root.
请注意,我们的应用程序、系统和模块目录都在 Web 根目录之外。
回答by Dylan
On some hosts, I think specficially when running PHP in CGI mode, you have to change
在某些主机上,我特别认为在 CGI 模式下运行 PHP 时,您必须更改
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ index.php/$1 [L]
to
到
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [L]
in your htaccess. So basically you can use the kohana recommended setup, simply replacing index.php/$1with index.php?/$1
在您的 htaccess 中。所以基本上你可以使用kohana推荐的设置,只需替换index.php/$1为index.php?/$1
回答by Gumbo
Try this mod_rewrite rule:
试试这个 mod_rewrite 规则:
##代码##回答by Marcin Ignac
For those who get "forbidden error" 403 on OSX with default .htaccess be sure to add as the first line in .htaccess
对于那些在 OSX 上使用默认 .htaccess 获得“禁止错误”403 的人,请务必将其添加为 .htaccess 中的第一行
Options +FollowSymLinks
选项 +FollowSymLinks
回答by Henry Tseng
Kohana 3.2 has a different convention. If you look in Kohana_URL you'll find the following function signature:
Kohana 3.2 有一个不同的约定。如果您查看 Kohana_URL,您会发现以下函数签名:
##代码##where $index is default to TRUE. By passing a $index FALSE you'll remove the index.php reference.
其中 $index 默认为 TRUE。通过传递 $index FALSE,您将删除 index.php 引用。

