2011-04-16 42 views
1

目前,使用Kohana的3.1,我可以通过访问我的控制器:如何从网址中的Kohana删除的index.php 3.1

http://localhost/kohana/index.php/admin

不过,我想访问它们没有“的index.php “在中间,如:

http://localhost/kohana/admin

我怎么能这样做?我是否需要更改我的.htaccess文件或某些配置选项?

我使用提供的Kohana中的.htaccess:

# Turn on URL rewriting 
RewriteEngine On 

# Installation directory 
RewriteBase/

# Protect hidden files from being viewed 

    Order Deny,Allow 
    Deny From All 


# Protect application and system files from being viewed 
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [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]

回答

5

更改RewriteBase指令到该应用程序。你会:

# Installation directory 
RewriteBase /kohana/ 

另外,还要确保你在你的引导有正确base_url

+0

完美!本地主机上的任何人都应该注意,base_url或htaccess中不需要“localhost”。 (kohana 3.2对我来说) – 2012-04-26 03:59:46

6

但是,如果你使用Rewritebase /kohana/,你仍然会在url中获得index.php。 我使用的Kohana 3,所以我去bootstrap.php和改变这一点:

Kohana::init(array(
    'base_url' => '/', 
    'index_file' => '', 
)); 
+0

这真是诀窍,谢谢! – 2014-01-22 10:27:19

0

看来你错过kohaha文件夹。 它应该是这样的: Kohana :: init(array( 'base_url'=>'/ kohana /', 'index_file'=>'', ));

1

在一些网站上,我看到的.htaccess建议:

# Rewrite all other URLs to index.php/URL 
RewriteRule .* index.php?kohana_uri=$0 [PT,L,QSA] 
0

打开URL中加入以下代码重写:

在.htaccess:

RewriteEngine On 
# Installation directory 
RewriteBase/

在引导:

Kohana::init(array('base_url' => '', 'index_file' => ''));