求助PHP伪静态,如何将动态PHP页面改为伪静态页面

/index.php?page=2
如何将上面的url转伪静态
/index/2.html

很简单的分页代码,我粘上来,麻烦帮我改一下,我只是php新手

<?php
//分页代码
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
echo "<div style='padding:10px' align='center'>共有".$pages."页(".$page."/".$pages.")";
if ($page > 1)
{
echo " <a href='?page=".$first."'>首页</a> ";
echo " <a href='?page=".$prev."'>上一页</a> ";
}

if ($page < $pages)
{
echo " <a href='?page=".$next."'>下一页</a> ";
echo " <a href='?page=".$last."'>尾页</a> ";
echo "</div>";
}
//分页代码
mysql_free_result($result);
mysql_close();
?>

  伪静态实际上就是把 index.php?act=about&cid=1 将这种形式的动态路径用 about-1.html 这种形式输出,也就是说浏览器每次访问about-1.html地址能打开相应的index.php?act=about&cid=1动态网址。

伪静态的实现本质上是配置服务器进行路径转换,根据不同的服务器环境,配置方法也不太一样,PHP+iis6的话就要配置httpd.ini文件,php+iis7就要配置web.config,PHP+apache就要配置.htaccess文件(或者httpd.conf)

.htaccess(或者httpd.conf)文件的规则示例:
RewriteEngine on
RewriteRule ^/?(index|guestbook|online)\.html$ index\.php [L]
RewriteRule ^/?(eindex)\.html$ index\.php?act=$1 [L]
RewriteRule ^/?(index|guestbook|online)-([0-9]+).html$ index\.php\?p=$2 [L]
RewriteRule ^/?([a-z0-9]+)_([0-9]+).html$ index\.php\?act=$1&id=$2 [L]
RewriteRule ^/?([a-z0-9]+)-([0-9]+).html$ index\.php\?act=$1&cid=$2 [L]
RewriteRule ^/?([a-z0-9]+)-([0-9]+)-([0-9]+).html$ index\.php\?act=$1&cid=$2&p=$3 [L]

httpd.ini示例:
[ISAPI_Rewrite]
RepeatLimit 32
# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [F,I,O]
# Block external access to the Helper ISAPI Extension
RewriteRule .*\.isrwhlp / [F,I,O]
RewriteRule ^/(index|guestbook|online)\.html$ /$1\.php
RewriteRule ^/(eindex).html$ /index\.php\?act=$1
RewriteRule ^/(index|guestbook|online)-([0-9]+).html$ /$1\.php\?p=$2
RewriteRule ^/([a-z0-9]+)_([0-9]+).html$ /index\.php\?act=$1&id=$2
RewriteRule ^/([a-z0-9]+)-([0-9]+).html$ /index\.php\?act=$1&cid=$2
RewriteRule ^/([a-z0-9]+)-([0-9]+)-([0-9]+).html$ /index\.php\?act=$1&cid=$2&p=$3
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-08-02
你咋发两遍?。。。
=============
首先要确定你的Apache启用了mod_rewrite模块,并且将http.conf文件中网站所在目录的AllowOverride None 改为 AllowOverride all
然后在程序目录下创建一个名为 .htaccess的文件
将以下内容写入这个文件里:

RewriteEngine On
RewriteRule ^index/([0-9]+)\.html$ index.php?page=$1本回答被网友采纳
第2个回答  2009-08-02
可以把php的后缀直接换成.HTML
但是得把PHP的文件类型增加一个Html的!
第3个回答  2009-08-06
smarty模板应该可以。
第4个回答  2009-08-09
恩,对,二楼的说的对! 支持,就是这样的

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网