2011-02-08 33 views
0

我使用httaccess mod_rewrite產品網站。httacess:我怎麼能最小化規則

當產品將是添加,

我創建的產品類別中的URL 像

層級
 
1) http://www.example.com/Place-an-ad/Cars/Mazda/mazda-y/mazda-y-2/ 4 levels here 
2) http://www.example.com/Place-an-ad/Books/Science/     2 levels here 
3) http://www.example.com/Place-an-ad/Realestate/Apprtments/small/ 3 levels here 

類別可以是2,3或4級

我把這在httacces,雖然我不想重複。

 
RewriteRule ^Place-an-ad/(.*)/(.*)/(.*)/(.*)/(.*)/?$ new_ad.php?c1=$1&c2=$2&c3=$3&c4=$4 [NC,L] # for 4 level categories 
RewriteRule ^Place-an-ad/(.*)/(.*)/(.*)/(.*)/?$ new_ad.php?c1=$1&c2=$2&c3=$3 [NC,L] # for 3 level categories 
RewriteRule ^Place-an-ad/(.*)/(.*)/(.*)/?$ new_ad.php?c1=$1&c2=$2 [NC,L] # for 2 level categories 
RewriteRule ^Place-an-ad/(.*)/(.*)/?$ new_ad.php?c1=$1 [NC,L] # for 1 level category 

任何一個都可以縮短這個範圍,以便所有類別都可以通過一條規則處理。

感謝

回答

0

這將是很容易做的這種使用你的網站是寫在哪個服務器端語言(如PHP)的URL重寫。如果你有這些URL存儲在數據庫中,你可以添加表列來存儲每個URL被調用時應執行的腳本的名稱。

+0

有什麼進一步的建議嗎? – 2011-02-09 06:04:02

相關問題