RewriteEngine On
#RewriteCond %{ENV:SCRIPT_URL} (?:index|dispbbs)[-0-9]+/.html
RewriteRule ^(.*?(?:index|dispbbs))-([-0-9]+)/.html 1.php?__is_apache_rewrite=1&__rewrite_arg=2
</IfModule>
RewriteCond %{QUERY_STRING} (?:boardid|page|id|replyid|star|skin)/=/d+ [NC]
RewriteRule ^(.*(?:index|dispbbs))/.asp 1.php?{tolowercase:%{QUERY_STRING}}&__is_apache_rewrite=1
/*
功能:PHP頁面僞靜態化
具體用法:
實現效果爲:test.php/year/2006/action/_add.html
mod_rewrite();
$yearn=$_GET["year"];//結果爲'2006'
$action=$_GET["action"];//結果爲'_add'
*/
function mod_rewrite(){
global $_GET;
$nav=$_SERVER["REQUEST_URI"];
$script_name=$_SERVER["SCRIPT_NAME"];
$nav=substr(ereg_replace("^$script_name","",urldecode($nav)),1);
$nav=preg_replace("/^.ht(m){1}(l){0,1}$/","",$nav);//這句是去掉尾部的.html或.htm
$vars = explode("/",$nav);
for($i=0;$i<Count($vars);$i+=2){
$_GET["$vars[$i]"]=$vars[$i+1];
}
return $_GET;
}
?>
//利用server變量 取得PATH_INFO信息 該例中爲 /1,100,8630.html 也就是執行腳本名後面的部分
if(@$path_info =$_SERVER["PATH_INFO"]){
//正則匹配一下參數
if(preg_match("///(/d+),(/d+),(/d+)/.html/si",$path_info,$arr_path)){
$gid =intval($arr_path[1]); //取得值 1
$sid =intval($arr_path[2]); //取得值100
$softid =intval($arr_path[3]); //取得值8630
}else die("Path:Error!");
//相當於soft.php?gid=1&sid=100&softid=8630
}else die('Path:Nothing!');
//就是這麼簡單了。~)
?>