2014-02-08 67 views
0
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(\w+)/((\w+))?$ ?page=$1&other=$3 [L] 
RewriteRule ^(\w+)(/(\w+))?$ ?page=$1&other=$3 [L] 

這樣做是什麼讓它如此,如果用戶將在mysite.com/blarg和/ blarg是不是一個真正的目錄或文件,它會發送thme to index.php?page = blarg的.htaccess只有掌權如果滿足這兩個條件

但是,當我去mysite.com/iphone(這是一個真正的目錄,而不是一個文件)我引導到mysite.com/iphone/?page=iphone &其他=

回答

0

這是因爲最後RewriteRule存在與RewriteCond一致。請記住,RewriteCond僅適用於非常接下來的RewriteRule

使用此代碼:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

RewriteRule ^(\w+)/((\w+))?$ ?page=$1&other=$3 [L] 
RewriteRule ^(\w+)(/(\w+))?$ ?page=$1&other=$3 [L]