PHP伪静态化页面的实现

 

方法一:
一 打开 Apache 的配置文件 httpd.conf 。
二 将#LoadModule rewrite_module modules/mod_rewrite前面的#去掉
三 在 httpd.conf中添加:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{ENV:SCRIPT_URL} (?:index|dispbbs)[-0-9]+/.html
RewriteRule ^(.*?(?:index|dispbbs))-([-0-9]+)/.html 1.php?__is_apache_rewrite=1&__rewrite_arg=2
</IfModule>
四 要实现asp帖子URL到php帖子的映射,在 第三步的<IfModule mod_rewrite.c>和</IfModule>之间添加:
RewriteMap tolowercase int:tolower
RewriteCond %{QUERY_STRING} (?:boardid|page|id|replyid|star|skin)/=/d+ [NC]
RewriteRule ^(.*(?:index|dispbbs))/.asp 1.php?{tolowercase:%{QUERY_STRING}}&__is_apache_rewrite=1
五 保存httpd.conf并重启Apache。
方法二:
<?php
/*
功能:PHP页面伪静态化
具体用法:
实现效果为:test.php/year/2006/action/_add.html
mod_rewrite();
$yearn=$_GET["year"];//结果为'2006'
$action=$_GET["action"];//结果为'_add'
*/
function mod_rewrite(){
global $_GET;
$nav=$_SERVER["REQUEST_URI"];
$script_name=$_SERVER["SCRIPT_NAME"];
$nav=substr(ereg_replace("^$script_name","",urldecode($nav)),1);
$nav=preg_replace("/^.ht(m){1}(l){0,1}$/","",$nav);//这句是去掉尾部的.html或.htm
$vars = explode("/",$nav);
for($i=0;$i<Count($vars);$i+=2){
$_GET["$vars[$i]"]=$vars[$i+1];
}
return $_GET;
}
?>
<?php
//利用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!');
//就是这么简单了。~)
?>
apache 伪静态设置方法
一 打开 apache 的配置文件 httpd.conf
二 将#loadmodule rewrite_module modules/mod_rewrite 前面的#去掉
三 打开 httpd-vhosts.conf
四 修改如下:
<VirtualHost *:80>
Options FollowSymLinks
ServerAdmin kevinliyong@163.com
DocumentRoot d:/myphp/sophiacn
ServerName sophiacn.com
ErrorLog logs/sophiacn.com-error_log
CustomLog logs/sophiacn.com-access_log common
php_admin_value open_basedir "d:/myphp/sophiacn;C:/WINDOWS/TEMP"
RewriteEngine on
RewriteRule ^(.*)/list-([0-9]+)-([0-9]+)/.html$ $1/list.php?sort_id=$2&page=$3
RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)/.html$ $1/article.php?sort_id=$2&id=$3
</VirtualHost>
重启 apache
.htaccess 方法:
RewriteEngine On
RewriteBase /
RewriteRule ^list-([0-9]+)-([0-9]+)/.html$ list.php?sort_id=$1&page=$2
RewriteRule ^article-([0-9]+)-([0-9]+)/.html$ article.php?sort_id=$1&id=$2
Referece  http://cache.baidu.com/c?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值