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

来源:百度知道 编辑:UC知道 时间:2024/06/26 02:07:26
/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();
?>

你咋发两遍?。。。
=============
首先要确定你的Apache启用了mod_rewrite模块,并且将http.conf文件中网站所在目录的AllowOverride None 改为 AllowOverride all
然后在程序目录下创建一个名为 .htaccess的文件
将以下内容写入这个文件里:

RewriteEngine On
RewriteRule ^index/([0-9]+)\.html$ index.php?page=$1

  伪静态实际上就是把 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\.ph