php函数实现url静态化

2009-08-26   来源:站长日记       编辑:沧海桑田   类别:PHP 教程    转载到:    发表评论

程序都是动态的,想实现url优化,但是没有服务器权限,很简单,可以从$_SERVER[”REQUEST_URI”]和$_SERVER[’PATH_INFO’]来
例如原网站//www.faceosho.com/test.php?a=1&b=2&c=3
使用了 mode_rewrite 函数后,可以用 //www.faceosho.com/test.php/a/1/b/2/c/3来访问了,而且程序基本不用修改.

function mod_rewrite()
{
  if ( isset ($_SERVER ['PATH_INFO']))
  {
        $url  =  substr ($_SERVER ['PATH_INFO'] , 1 );
        $url  =  explode ('/',$url );
         foreach ($url  as $key  =>$value )
   {
    if ($key % 2 != 1 )
   {
    if ($value != ’’ )$_GET [$value ] =$url [$key + 1 ];
     $querystring [] = $value .'='.$url [$key + 1 ];
    }
        }
        $_SERVER ['QUERY_STRING'] = implode ( " & " ,$querystring );
      $_SERVER ['PHP_SELF'] = substr ($_SERVER ['PHP_SELF'], 0 , strpos ($_SERVER ['PHP_SELF'] ,'.php') + 4 );
        $_SERVER ['REQUEST_URI'] =$_SERVER ['PHP_SELF'].'?'.$_SERVER ['QUERY_STRING'];
 }
}  
mod_rewrite();  
//www.faceosho.com/test.php/a/1/b/2/c/3 
echo '

';
echo  " GET数组如下:
" ;
print_r ($_GET );
Array 
(
  [a] =>  1 
  [b] =>  2 
  [c] =>  3 
)

0

0
0|0 | 鲜花 VS 砸蛋 | 17阅读 0评论
 
不想登录?直接点击发布即可作为游客留言。
昵称  邮箱 网站 验证码 = 1+1