求PHP伪静态规则编写,地址带标题字付串参数和ID号参数:
要求地址:products1.php?title=Handbags_&_bags&sort_id=13  变成Handbags_&_bags_13.html
products1.php?title=Children_s_Wear&sort_id=19 变成 Children_s_Wear_19.html
products1.php?title=Hair_Care_Shop&sort_id=20 变成   Hair_Care_Shop_20.html
products1.php?title=A_&_F_/_Hollister_Long_Shirts&sort_id=20  变成  A_&_F_/_Hollister_Long_Shirts_171.html
这样的htaccess规则该怎么写呀?先谢了。

解决方案 »

  1.   

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^(.*)_([0-9]+)\.html$ products1.php?title=$1&sort_id=$2
    </IfModule>
      

  2.   

    前3个规则可以用:RewriteRule ([a-zA-Z]+_[a-zA-Z&]+_[a-zA-Z]+)_(\d+)\.html$  products1.php?title=$1&sort_id=$2([a-zA-Z]+_[a-zA-Z&]+_[a-zA-Z]+)可以匹配Handbags_&_bags、Children_s_Wear、Hair_Care_Shop但是最后一个products1.php?title=A_&_F_/_Hollister_Long_Shirts&sort_id=20 变成 A_&_F_/_Hollister_Long_Shirts_171.html
    这个我觉得没有规律数字对应都不是绝对的,应该需要就具体数字单独写一条适应的,如:
     
    RewriteRule  A_&_F_/_Hollister_Long_Shirts_171.html$  products1.php?title=A_&_F_/_Hollister_Long_Shirts&sort_id=20