PHP代码伪静态怎么写?其实很简单的!

比如下面这段,我要输出为伪静态 show-文章id 应该怎么写呢?

<?php
$result = mysql_query(“SELECT * FROM dxju where fl=’生活常识’ ORDER BY itemid DESC limit 0,10”);
while($row = mysql_fetch_array($result))
{
$tm = mysubstr($row[‘tm’],0,45);
echo “<p><a href=show.php?itemid=”.$row[‘itemid’];
echo ” title=”.$tm.” >”;
echo $tm;
echo “</a></p>”;
}
?>
</ul>

我们直接把echo “<p><a href=show.php?itemid=”.$row[‘itemid’];改成echo “<li><a href=/show-“.$row[‘itemid’].””;

<?php
$result = mysql_query(“SELECT * FROM dxju where fl=’生活常识’ ORDER BY itemid DESC limit 0,10”);
while($row = mysql_fetch_array($result))
{
$tm = mysubstr($row[‘tm’],0,70);
echo “<li><a href=/show-“.$row[‘itemid’].””;
echo ” title=”.$tm.” >”;
echo $tm;
echo “</a></li>”;
}
?>

 

然后我们在伪静态规则里配置伪静态规则就好了!

比如上面的伪静态规则就是:rewrite ^/show-([0-9]+)\$ /show.php?itemid=$1;

Nginx环境下的,其他的环境转换一下就好了!

发表回复