2011-02-08 59 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