Heim  >  Artikel  >  Backend-Entwicklung  >  PHP伪静态写法附代码_php技巧

PHP伪静态写法附代码_php技巧

WBOY
WBOYOriginal
2016-05-17 09:36:361305Durchsuche

比如这个网页
http://www.jb51.net/soft.php/1,100,8630.html

其实处理的脚本是soft.php 参数为1,100,8630

相当于soft.php?a=1&b=1=100&c=8630 只不过这样的URL太难记。搜索引擎也不喜欢。

真静态只是完全生成了HTML。

客户端访问的时候直接输出。不用脚本解释。在流量非常大的时候(比如每天有上百万的访问量的时候)会起到很好的效果。也就是说服务器端实实在在的存在这个HTML页面。

当然在你网站的流量没有那么大的时候。URL重写是最好的方法(个人观点,大流量的时候可以考虑负载均衡了。同样没有关系)

附URL重写的方法有很多种,APACHE,IISREWRITE。甚至PHP脚本都可以直接处理。比如上例中就是PHP脚本直接处理(该方法好处是大流量的时候直接减轻WEB伺服器的压力。PS:同样也是个人观点:

================================================

下面以程序为例讲一下PHP伪静态的程序实现方法,其实这方法我之前已经有在其它论坛社区发过

程序为例:

http://www.jb51.net/soft.php/1,100,8630.html

复制代码 代码如下:

//利用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!');
//就是这么简单了。~) 
 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn