2009-06-14 149 views
2

我需要兩個條件規則。背景:兩個mod重寫規則

 
http://www.domain.com/.htaccess 
http://www.domain.com/index.php 
http://www.domain.com/admin/index.php 

我都重寫規則:

 
ROOT: 
RewriteEngine On 
RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule ^(.*/)([^/]+)/([^/]+) $1?$2=$3&%1 [L] 
RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule ^([^/]+)/ $1.php?%1 [L] 

ADMIN: 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-z]+?)/([a-z]+?)/(.*)$ index.php?model=$1&view=$2&params=$3 [L,NS] 

我需要以某種方式只對根級別使用一個.htaccess文件這兩個規則,但規則ADMIN只有當網址申請http://www.domain.com/admin/foo/bar/something/else和ROOT規則適用於http://www.domain.com/foo/bar/something/else

先謝謝你,我已經殺了整整一天,試圖做到這一點,當一個工程時,另一個給我一個「未找到」頁錯誤。

克里斯

+0

重複的http://stackoverflow.com/questions/992054/subfolders-and-modrewrew – jitter 2009-06-14 15:26:06

+0

抖動:你能回答我的問題,然後請?爲什麼發表評論,如果它不具有建設性? – Torez 2009-06-14 16:17:46

回答

1

我會使用這樣的:

RewriteEngine On 

# /admin/ rule 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^admin/([a-z]+)/([a-z]+)/(.*)$ admin/index.php?model=$1&view=$2&params=$3 [L,NS] 
RewriteRule ^admin/ - [L] 

# other rules 
RewriteRule ^(.*/)([^/]+)/([^/]+)$ $1?$2=$3 [L,QSA] 
RewriteRule ^([^/]+)/ $1.php [L,QSA] 

QSA標誌(查詢字符串追加)更換RewriteCond %{QUERY_STRING} (.*)指令。

2
RewriteCond %{REQUEST_URI} !^/admin/ 
RewriteCond %{QUERY_STRING} (.*) 
RewriteRule ^(.*/)([^/]+)/([^/]+) $1?$2=$3&%1 [L] 
RewriteCond %{REQUEST_URI} !^/admin/ 
RewriteCond %{QUERY_STRING} (.*) 
RewriteRule ^([^/]+)/ $1.php?%1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^admin/([a-z]+?)/([a-z]+?)/(.*)$ /admin/index.php?model=$1&view=$2&params=$3 [L,NS]