在 httpd.conf中添加:
RewriteEngine On RewriteRule ^(.*).html$ index\.php?main_page=$1&%{QUERY_STRING} [L] RewriteRule ^(.*)-p-(.*).html$ index\.php?main_page=product_info&products_id=$2&%{QUERY_STRING} [L] RewriteRule ^(.*)-c-(.*).html$ index\.php?main_page=index&cPath=$2&%{QUERY_STRING} [L]
这个是外贸购物系统zencart里面所用的。那如果你的空间不支持伪静态的时候,该怎么处理这个问题呢?主要用到的就是$_SERVER["REQUEST_URI"]这个属性:
$nav=$_SERVER["REQUEST_URI"]; $script_name=$_SERVER["SCRIPT_NAME"]; $nav1=ereg_replace(".html","",substr(ereg_replace("$script_name","",urldecode($nav)),1)); $vars = explode("/",$nav1); //$id=$vars[1];
其实$vars这个的到的就是一数组,如果你的链接是这样的,
http://phpkfz.com/rewrite.php/product/id/001.html
则数组就是$vars[0]=product,$vars[1]=id,$vars[2]=001。
就是这么简单,不过这种伪静态一定要在地址加上PHP文件,有兴趣的可以试一试。