第一种伪静态页面(拟静态)的方法(针对有服务器权限的):

http.conf 里 把mod_rewrite的#去掉

htacc 把 前面的option 改为all

RewriteEngine on
RewriteRule ^/t_(.*).html$ /test.php?id=$1? 输出成html格式

RewriteRule ^/t_(.*)/$ /test.php?id=$1 输出目录格式 *localhost/t_333/*

第二种伪静态页面(拟静态)的方法(针对无服务器权限的):

在根目录建文件 .htaccess

.htaccess

RewriteEngine on
RewriteRule ^/test.html$ /test.php?id=$1?

#ErroeDocument 404 /test.php

关于规则的写法,请参考其它文档。

第三种伪静态页面(拟静态)的方法(用程序进行处理)分为四种方式:

	<li><strong><span style="color: #006699"><?php</span></strong>?</li>
	<li>//伪静态方法一 ?</li>
	<li>?</li>
	<li>//?localhost/php100/test.php?id|[email protected]|2 ?</li>
	<li>$<span style="color: #ff0000">Php2Html_FileUrl</span>?=?$_SERVER["REQUEST_URI"]; ?</li>
	<li>echo?$Php2Html_FileUrl."<strong><span style="color: #006699"><br></span></strong>";//?/php100/test.php?id|[email protected]|2 ?</li>
	<li>$<span style="color: #ff0000">Php2Html_UrlString</span>?=?<span style="color: #0000ff">str_replace</span>("?","",str_replace("/",?"",?strrchr(strrchr($Php2Html_FileUrl,?"/"),"?"))); ?</li>
	<li>echo?$Php2Html_UrlString."<strong><span style="color: #006699"><br></span></strong>";//?id|[email protected]|2 ?</li>
	<li>$<span style="color: #ff0000">Php2Html_UrlQueryStrList</span>?=?<span style="color: #0000ff">explode</span>("@",?$Php2Html_UrlString); ?</li>
	<li>print_r($Php2Html_UrlQueryStrList);//?Array?(?[0]?=<strong><span style="color: #006699">></span></strong>?id|1?[1]?=<strong><span style="color: #006699">></span></strong>?action|2?) ?</li>
	<li>echo?"<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>foreach($Php2Html_UrlQueryStrList?as?$Php2Html_UrlQueryStr) ?</li>
	<li>{ ?</li>
	<li>$<span style="color: #ff0000">Php2Html_TmpArray</span>?=?<span style="color: #0000ff">explode</span>("|",?$Php2Html_UrlQueryStr); ?</li>
	<li>print_r($Php2Html_TmpArray);//?Array?(?[0]?=<strong><span style="color: #006699">></span></strong>?id?[1]?=<strong><span style="color: #006699">></span></strong>?1?)?;?Array?(?[0]?=<strong><span style="color: #006699">></span></strong>?action?[1]?=<strong><span style="color: #006699">></span></strong>?2?) ?</li>
	<li>echo?"<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>$_GET[$Php2Html_TmpArray[0]]?=?$Php2Html_TmpArray[1]; ?</li>
	<li>} ?</li>
	<li>//echo?'假静态:$_GET变量<strong><span style="color: #006699"><br</span></strong>?<strong><span style="color: #006699">/></span></strong>'; ?</li>
	<li>print_r($_GET);?//?Array?(?[id|[email protected]|2]?=<strong><span style="color: #006699">></span></strong>?[id]?=<strong><span style="color: #006699">></span></strong>?1?[action]?=<strong><span style="color: #006699">></span></strong>?2?) ?</li>
	<li>echo?"<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>echo?"<strong><span style="color: #006699"><hr></span></strong>"; ?</li>
	<li>echo?$_GET[id]."<strong><span style="color: #006699"><br></span></strong>";//?1 ?</li>
	<li>echo?$_GET[action];//?2 ?</li>
	<li><strong><span style="color: #006699">?></span></strong>?</li>
	<li><strong><span style="color: #006699"><?php</span></strong>?</li>
	<li>//伪静态方法二 ?</li>
	<li>?</li>
	<li>//?localhost/php100/test.php/1/2 ?</li>
	<li>$<span style="color: #ff0000">filename</span>?=?<span style="color: #0000ff">basename</span>($_SERVER['SCRIPT_NAME']); ?</li>
	<li>echo?$_SERVER['SCRIPT_NAME']."<strong><span style="color: #006699"><br></span></strong>";//?/php100/test.php ?</li>
	<li>echo?$filename."<strong><span style="color: #006699"><br></span></strong>";//?test.php ?</li>
	<li>?</li>
	<li>if(strtolower($filename)=='test.php'){ ?</li>
	<li>?if(!empty($_GET[id])){ ?</li>
	<li>??$<span style="color: #ff0000">id</span>=<span style="color: #0000ff">intval</span>($_GET[id]); ?</li>
	<li>??echo?$id."<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>??$<span style="color: #ff0000">action</span>=<span style="color: #0000ff">intval</span>($_GET[action]); ?</li>
	<li>??echo?$action."<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>?}else{ ?</li>
	<li>??$<span style="color: #ff0000">nav</span>=$_SERVER['REQUEST_URI']; ?</li>
	<li>??echo?"1:".$nav."<strong><span style="color: #006699"><br></span></strong>";//?/php100/test.php/1/2 ?</li>
	<li>??$<span style="color: #ff0000">script</span>=$_SERVER['SCRIPT_NAME']; ?</li>
	<li>??echo?"2:".$script."<strong><span style="color: #006699"><br></span></strong>";//?/php100/test.php ?</li>
	<li>??$<span style="color: #ff0000">nav</span>=<span style="color: #0000ff">ereg_replace</span>("^$script","",urldecode($nav)); ?</li>
	<li>??echo?$nav."<strong><span style="color: #006699"><br></span></strong>";?//?/1/2 ?</li>
	<li>??$<span style="color: #ff0000">vars</span>=<span style="color: #0000ff">explode</span>("/",$nav); ?</li>
	<li>??print_r($vars);//?Array?(?[0]?=<strong><span style="color: #006699">></span></strong>?[1]?=<strong><span style="color: #006699">></span></strong>?1?[2]?=<strong><span style="color: #006699">></span></strong>?2?) ?</li>
	<li>??echo?"<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>??$<span style="color: #ff0000">id</span>=<span style="color: #0000ff">intval</span>($vars[1]); ?</li>
	<li>??$<span style="color: #ff0000">action</span>=<span style="color: #0000ff">intval</span>($vars[2]); ?</li>
	<li>?} ?</li>
	<li>?echo?$id.'&'.$action; ?</li>
	<li>} ?</li>
	<li><strong><span style="color: #006699">?></span></strong>?</li>
	<li><strong><span style="color: #006699"><?php</span></strong>?</li>
	<li>//伪静态方法三 ?</li>
	<li>?</li>
	<li>?</li>
	<li>function?mod_rewrite(){ ?</li>
	<li>global?$_GET; ?</li>
	<li>$<span style="color: #ff0000">nav</span>=$_SERVER["REQUEST_URI"]; ?</li>
	<li>echo?$nav."<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>$<span style="color: #ff0000">script_name</span>=$_SERVER["SCRIPT_NAME"]; ?</li>
	<li>echo?$script_name."<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>$<span style="color: #ff0000">nav</span>=<span style="color: #0000ff">substr</span>(ereg_replace("^$script_name","",urldecode($nav)),1); ?</li>
	<li>echo?$nav."<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>$<span style="color: #ff0000">nav</span>=<span style="color: #0000ff">preg_replace</span>("/^.ht(m){1}(l){0,1}$/","",$nav);//这句是去掉尾部的.html或.htm ?</li>
	<li>echo?$nav."<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>$<span style="color: #ff0000">vars</span>?=?<span style="color: #0000ff">explode</span>("/",$nav); ?</li>
	<li>print_r($vars); ?</li>
	<li>echo?"<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>for($<span style="color: #ff0000">i</span>=<span style="color: #0000ff">0</span>;$i<strong><span style="color: #006699"><Count</span></strong>($vars);$i+=2){ ?</li>
	<li>$_GET["$vars[$i]"]=$vars[$i+1]; ?</li>
	<li>} ?</li>
	<li>return?$_GET; ?</li>
	<li>} ?</li>
	<li>mod_rewrite(); ?</li>
	<li>$<span style="color: #ff0000">year</span>=$_GET["year"];//结果为'2006' ?</li>
	<li>echo?$year."<strong><span style="color: #006699"><br></span></strong>"; ?</li>
	<li>$<span style="color: #ff0000">action</span>=$_GET["action"];//结果为'_add' ?</li>
	<li>echo?$action; ?</li>
	<li><strong><span style="color: #006699">?></span></strong>?</li>
	<li><strong><span style="color: #006699"><?php</span></strong>?</li>
	<li>//伪静态方法四 ?</li>
	<li>?</li>
	<li>//利用server变量?取得PATH_INFO信息?该例中为?/1,100,8630.html???也就是执行脚本名后面的部分 ?</li>
	<li>if(@$<span style="color: #ff0000">path_info</span>?=$_SERVER["PATH_INFO"]){ ?</li>
	<li>//正则匹配一下参数 ?</li>
	<li>if(preg_match("//(d+),(d+),(d+).html/si",$path_info,$arr_path)){ ?</li>
	<li>$<span style="color: #ff0000">gid</span>?????=<span style="color: #0000ff">intval</span>($arr_path[1]);?//取得值?1 ?</li>
	<li>$<span style="color: #ff0000">sid</span>?????=<span style="color: #0000ff">intval</span>($arr_path[2]);???//取得值100 ?</li>
	<li>$<span style="color: #ff0000">softid</span>???=<span style="color: #0000ff">intval</span>($arr_path[3]);???//取得值8630 ?</li>
	<li>}else?die("Path:Error!"); ?</li>
	<li>//相当于soft.php?<span style="color: #ff0000">gid</span>=<span style="color: #0000ff">1</span>&<span style="color: #ff0000">sid</span>=<span style="color: #0000ff">100</span>&<span style="color: #ff0000">softid</span>=<span style="color: #0000ff">8630</span>?</li>
	<li>}else?die('Path:Nothing!'); ?</li>
	<li><strong><span style="color: #006699">?></span></strong>?</li>

以上就是本文介绍的几种PHP伪静态的方法,希望对大家有所帮助。