0

===== CLARIFICATION =====

Please note this, there are hundred of answers to posts similar to this one, but people only cover a part of the problem, not the real one i'm asking here.

=====

I'm using Kohana 3.2, and i want to completely remove index.php from the url. For example, i want to access to the controller foo, action bar.

Normally, with bootstrap and htaccess correctly setted up, i can access like this:

www.domain.com/foo/bar.

But i can also access like this:

www.domain.com/index.php/foo/bar

I want to allow users to ONLY access like the first way, and not like the second way.

I have this section in bootstrap.php:

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

i tried taking off index_file line, changing its value to FALSE, and i am still able to access foo/bar both ways.

I think the solution is modifying htaccess, but i tried some changes and it isnt working as i want. I'm using the original htaccess which came with kohana:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /knisu/

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# 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]

Any help would be appreciated :)

EDIT: I found an answer that could make it work in another post:

  # Redirect from:
  # http://localhost/index.php/welcome
  # to
  # http://localhost/welcome
  #
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule ^index\.php/?(.*)?$ $1 [R,L]

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ ?/$1 [L]

The thing is, the author says: "this works but the problem is with the files and dirs that exists he must put the complete path for the images, css, js, etc... I will fix later"

May be that helps to find the final solution?

4

1 回答 1

0

我认为使用原始的 htaccess 更好,但有改进。

之后...

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

这应该做“index.php/”的重定向,

# Redirect any "index.php/user/profile/" to "/user/profile/"
RewriteRule ^index.php/(.*)$ /$0 [L,R=302]

以我的经验,通过控制器传递 css/js 比纯 apache/nginx 请求慢。

于 2012-07-02T18:05:24.613 回答