2011-04-16 41 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' => ''));