2013-06-18 21 views
1

我有我以爲工作了重寫規則:RewriteRule否決了第二條規則並GET了index.php?

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/(.*)$ index.php?lang=$1&page=$2 
RewriteRule ^(.*)/editor/(.*)$ index.php?lang=$1&page=editor&func=$2 

當我在第一級上做$_GET['lang'](郎,只有頁),它返回的語言。但是如果我在第二級(lang,page和func)嘗試它,我會得到index.php

我在做什麼錯?謝謝!

+0

什麼是第一級和什麼是第二級? 請注意,第一個重寫規則始終爲真。 。是'任何角色'的簽名卡,這包括'/' – Pinoniq

+0

@Pinoniq第一部重寫片。級別可能是一個令人困惑的事情來稱呼它。 –

回答

1

您沒有[L]標誌在第一次匹配後停止處理,您的第二條規則也會與第一條匹配。由於它更具體,請首先列出它,幷包括[L]。此外,而不是貪婪(.*)我建議([^/]+)一切匹配下一/

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# List this first, with [L] 
RewriteRule ^([^/]+)/editor/(.*)$ index.php?lang=$1&page=editor&func=$2 [L] 
# Then URIs not containing editor/ will match the other rule 
RewriteRule ^([^/]+)/(.*)$ index.php?lang=$1&page=$2 [L] 

如果CSS &圖像失敗,你可能需要移動RewriteCondeditor/規則之下,以確保條件只適用以最不具體​​的全面匹配:

RewriteRule ^([^/]+)/editor/(.*)$ index.php?lang=$1&page=editor&func=$2 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/(.*)$ index.php?lang=$1&page=$2 [L] 
+0

是的!這給了我合適的語言!只有我的樣式表和圖片無效。我在我的HTML中有一個基礎。我該如何解決這個問題? –

+0

@JayWit你是什麼意思在你的HTML基地?一個''標籤?添加一個'[L,R]'標誌並嘗試直接請求你的一個CSS文件,看看它被重寫到哪裏。 'RewriteCond'應該照顧那個...... –

+0

你可能需要在'RewriteRule'之前插入一個打破規則,就像http://stackoverflow.com/questions/1715765/have-some-rewriteconds-影響 - 多規則 –

相關問題