开发者

How to remove index.php from URLs in Kohana 3.1

Currently, using Kohana 3.1, I can access my controllers using:

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

However, I would like to access them without the "index.php" in the middle, as in:

http://localhost/kohana/admin

How can I do that? Do I need to change my .htaccess file or some config option?

I'm using the .htaccess provided with Kohana:

# 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_FILEN开发者_开发技巧AME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]


However, if you use Rewritebase /kohana/, you will still get index.php in the url. I'm using Kohana 3, so I go to bootstrap.php and change this:

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


Change the RewriteBase directive to where the application is. Yours would be:

# Installation directory
RewriteBase /kohana/

Also make sure you have the correct base_url in your bootstrap.


On some website I saw .htaccess suggestion:

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


It seems that you miss kohaha folder. It should be like this: Kohana::init(array( 'base_url' => '/kohana/', 'index_file' => '', ));


Turn on URL rewriting by adding the following code:

In .htaccess:

RewriteEngine On
# Installation directory
RewriteBase /

In Bootstrap:

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


You need to use 'index_file' => FALSE in bootstrap.php

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜