2013-04-09 24 views
1

我已經從我的工作有一個代碼點火項目工作,所以我試圖做到這一點了解了一些關於MVC:捕獲其間網址的所有實例/ /但如果文件

之前: 的index.php somepage.php secondpage.php

所有這些文件有「包括(頭),包括(頁腳)等等...

相反,我要捕捉的用戶是什麼頁面從url尋找 - >將它們重定向到索引,並且始終將頁眉和頁腳加載到該地方,唯一的變化就是內容。

所以我做了這個與我的htaccess:

<IfModule mod_rewrite.c> 
    Options +FollowSymLinks 
    Options +Indexes 
    RewriteEngine On 
    RewriteCond %{SCRIPT_FILENAME} !-d 
    RewriteCond %{SCRIPT_FILENAME} !-f 
    RewriteRule (.*)/(.*)/(.*)/(.*)/(.*)/(.*) index.php?page=$1&child=$2&grandchild=$3&cousin=$4&aunt=$5&uncle=$6 [NC,QSA,L] 
    RewriteRule (.*)/(.*)/(.*)/(.*)/(.*) index.php?page=$1&child=$2&grandchild=$3&cousin=$4&aunt=$5 [NC,QSA,L] 
    RewriteRule (.*)/(.*)/(.*)/(.*) index.php?page=$1&child=$2&grandchild=$3&cousin=$4 [NC,QSA,L] 
    RewriteRule (.*)/(.*)/(.*) index.php?page=$1&child=$2&grandchild=$3 [NC,QSA,L] 
    RewriteRule (.*)/(.*) index.php?page=$1&child=$2 [NC,QSA,L] 
    RewriteRule (.*^.css) index.php?page=$1 [NC,QSA,L] 
</IfModule> 

隨着心態,如果它的工作原理它是一個開始..但它不工作。首先我注意到我的CSS沒有加載..顯然-f沒有幫助,所以我添加了規則,但是/img/bg.png也不起作用。

我希望很明顯我正在嘗試捕獲url中//之間的任何單詞並將它們傳遞給索引作爲參數。你們知道是否有任何智能重寫規則,如果文件存在實際上忽略了重寫?

+0

嗯這可能適用於不重寫內部調用:http://stackoverflow.com/questions/11116087/url-rewriting-doesnt-rewrite-automatically我會試試看! :D – Alisso 2013-04-09 19:43:38

回答

0

我改變了我的邏輯。 我現在檢測到什麼頁面,並將其餘的保存到變量設置中, 這隻適用於thr? *後如你所說:

最終目前的解決方案:

<IfModule mod_rewrite.c> 
    Options +FollowSymLinks 
    Options +Indexes 
    RewriteEngine On 
    RewriteCond %{SCRIPT_FILENAME} !-d 
    RewriteCond %{SCRIPT_FILENAME} !-f 
    RewriteRule ^(.*?)/(.*) index.php?page=$1&settings=$2 [QSA,L] 

    RewriteCond %{SCRIPT_FILENAME} !-d 
    RewriteCond %{SCRIPT_FILENAME} !-f 
    RewriteRule ^(.*) index.php?page=$1 [QSA,L] 
</IfModule> 
1

RewriteCond s的應用到下一個,在你的情況下,只有第一,RewriteRule。如果你想使用它的每一個重寫規則,你必須重複它

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)/(.*?)/(.*?) index.php?page=$1&child=$2&grandchild=$3&cousin=$4&aunt=$5&uncle=$6 [QSA,L] 

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)/(.*) index.php?page=$1&child=$2&grandchild=$3&cousin=$4&aunt=$5 [QSA,L] 

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?) index.php?page=$1&child=$2&grandchild=$3&cousin=$4 [QSA,L] 
... 

這裏不需要[NC]標誌,因爲該模式不包含任何字母字符。

我也修改了一下模式,使用^作爲URL路徑的開始和非貪婪版本.*?,這使捕獲在第一個斜槓處停止。

+0

我不知道康達只申請「下一個規則」! – Alisso 2013-04-10 17:28:44

+0

?之後。*沒有爲我工作, – Alisso 2013-04-10 17:35:46

相關問題