如何从Kohana 3.1中的URL中删除index.php

时间:2011-04-16 11:40:23

标签: kohana url-routing

目前,使用Kohana 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]

6 个答案:

答案 0 :(得分:6)

但是,如果您使用Rewritebase /kohana/,您仍会在网址中获得index.php。 我正在使用Kohana 3,所以我转到bootstrap.php并改变它:

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

答案 1 :(得分:5)

将RewriteBase指令更改为应用程序所在的位置。你的将是:

# Installation directory
RewriteBase /kohana/

还要确保你的引导程序中有正确的base_url

答案 2 :(得分:1)

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

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

答案 3 :(得分:0)

您似乎错过了 kohaha 文件夹。 它应该是这样的: Kohana的::的init(阵列(     'base_url'=> '/ Kohana的/',     'index_file'=> ', ));

答案 4 :(得分:0)

通过添加以下代码启用URL重写:

在.htaccess中:

RewriteEngine On
# Installation directory
RewriteBase /

在Bootstrap中:

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

答案 5 :(得分:0)

您需要在bootstrap.php中使用'index_file' => FALSE

来源:http://kohanaframework.org/3.0/guide/kohana/tutorials/clean-urls

相关问题