2012-07-02 27 views
0

=====澄清=====Kohana的:完全刪除URL的index.php(不重複的問題)

請注意這一點,有答案的職位與此類似,但人們百隻涵蓋了一部分問題,而不是我在這裏問的真實問題。

=====

我用Kohana的3.2,我想從URL中完全刪除的index.php。例如,我想訪問控制器foo,操作欄。

正常情況下,自舉和htaccess的正確設置好的了,我可以像這樣訪問:

www.domain.com/foo/bar。

但我也可以像這樣訪問:

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

我想允許用戶像首隻訪問方式,而不是像第二種方式。

我在bootstrap.php中本節:

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

我試圖起飛index_file線,它的值更改爲FALSE,我仍然能夠訪問富/酒吧左右逢源。

我認爲解決方案正在修改htaccess,但我嘗試了一些更改,它不是按我的意願工作。我使用它附帶的Kohana原來的htaccess:

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

任何幫助,將不勝感激:)

編輯: 我找到了答案,可以使人們在另一篇工作:

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

事情是,作者說:「這工作,但問題是存在的文件和目錄,他必須把圖像,CSS,JS等的完整路徑...我會稍後修復」

可能有助於找到最終解決方案?

回答

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請求。

+0

你能說清楚嗎?我不知道我是否應該保留「RewriteCond%{REQUEST_FILENAME}!-f」和「RewriteCond%{REQUEST_FILENAME}!-d」。 我嘗試了兩種方式,並沒有按照我在那裏解釋的那樣工作。 – helpse