2013-05-18 31 views
0

我有一個基本的MVC結構的一個寧靜的URI設計:MVC htaccess的重寫 - 隱藏指數

mysite.com/appdir/:index/:controller/:action/ 

,我想隱藏索引路線參數,所以我的URI的樣子:

mysite.com/appdir/:controller/:action/ 

我的基本的文件夾結構爲:

appdir/ 
    app/ 
    -->Controller/ 
    -->Model/ 
    -->View/ 
    config/ 
    library/ 
    public/ 
    -->.htaccess 
    -->index.php 
    .htaccess 
    index.php 

APPDIR /的.htaccess:

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteRule ^$ public/ [L] 
    RewriteRule (.*) public/$1 [L] 
</IfModule> 

APPDIR /公/的.htaccess:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 
</IfModule> 
<IfModule !mod_rewrite.c> 
    ErrorDocument 404 index.php 
</IfModule> 

我似乎無法隱藏索引,我已經嘗試了一些重寫規則,似乎沒有任何工作。使用CodeIgniter,我通常可以添加RewriteRule ^(.*)$ index.php?/$1 [L,QSA]並解決問題,但是我一直在爲此工作3個小時而沒有成功。

回答

1

首先,永諾開始請求路徑與/ 所以第一規則應該這樣寫

RewriteEngine敘述上 重寫規則^ /(。*)$公共/ $ 1 [L]

然後我想在公共目錄的htaccess你應該使用

RewriteBase /公共

最後 - 爲什麼不設置公衆解決的文網絡服務器 的入口,並將所有規則放到單個文件中?在你的設置appdir/index.php永遠不可訪問。

+0

當你在''(per-server)上下文中時,要在RewriteRule中匹配的URL需要以'/'開始。在'.htaccess'文件(每個目錄)上下文中,URL必須*不*以'/'開頭。 – rpkamp