2011-05-20 40 views
1

我可以優化這些行嗎?優化模式_重寫行

 
RewriteRule ^contact/$ index.php?page=contact [L,QSA] 
RewriteRule ^service/$ index.php?page=service [L,QSA] 
RewriteRule ^ads/$  ads.php$1 [L,QSA] 
RewriteRule ^posts/$  posts.php$1 [L,QSA] 

回答

3

你可以概括一下「頁面」的東西。請記住,在大多數情況下,可維護性比線更少更重要。你不應該這樣做。

RewriteRule ^ads/$  ads.php$1 [L,QSA] 
RewriteRule ^posts/$  posts.php$1 [L,QSA] 
RewriteRule ^([^/]+)/$ index.php?page=$1 [L,QSA] 

我的修改是這樣的:它尋找任何特定的路線。如果不匹配,則最後一條規則將作爲回退並將頁面名稱追加到index.php?page=