php伪静态解析,浅谈PHP实现伪静态

2.在http.conf里面查找Options FollowSymLinks,将后面的AllowOverride None改成AllowOverride All。

这个时候兵分两路,有http.conf权限的可以自己在http.conf后面添加url rewrite规则

RewriteEngine On

RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2

第二路就只好在代码根目录建立.htaccess文件,这个文件建立比较简单,有3种方法,最简单的当然是建立1.htaccess然后记事本打开另存为.htaccess,另外就是cmd下rename和ftp软件修改。

3.rewrite规则

看个例子就懂了

RewriteEngine On

RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2

$是终止符,前面写个正则表达式,$1获取第一个子模式(小括号里面的东东),$2获取第二个子模式东东。

友情提示 ^是开头,不要忘记加了

如果有2个参数,也很简单,自行处理。

也就是说浏览器里面显示的如果是4.html(你的文件里面的链接写成.html的)的话,实际调用的是page.php?id=4,这样浏览器的输入栏都是html,达到了伪静态。

当然你改写不同正则,显示的url当然就不同了,随你喜欢的该。

遇见多行的话不要妄自加分号。如下才是对的:

RewriteEngine On

RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2

RewriteRule ^(.*)/index.html$ $1/index.php

RewriteRule ^(.*)/wenzhang.html$ $1/wenzhang.php

RewriteRule ^(.*)/gushi.html$ $1/gushi.php

RewriteRule ^(.*)/sanwen.html$ $1/sanwen.php

RewriteRule ^(.*)/zawen.html$ $1/zawen.php

RewriteRule ^(.*)/shige.html$ $1/shige.php

RewriteRule ^(.*)/riji.html$ $1/riji.php

RewriteRule ^(.*)/xiaoshuo.html$ $1/xiaoshuo.php

RewriteRule ^(.*)/contact.html$ $1/contact.php

综述就是网址重写引擎和指定一些重写规则.,尝试Faking URL Suffix(伪造URL后缀),看起来很静态化,提高了安全性和SEO友好度。

4.重启apache。

windows的httpd.conf很好找,在conf目录(我指的是你如果没用集成包的话)

Linux在opt/lampp/etc目录里面有httpd.conf(一般linux下推荐用Xampp按照包,安装在opt目录)

同样进行上面工作restart一下就ok

login as: root

Server refused our key

root@XXXXX.com's password:

Last login: Thu Jul 21 14:26:26 2011 from 112.65.219.75

[root@XXXXX ~]# who

root     pts/0        2011-07-21 14:32 (112.65.219.75)

[root@XXXXX ~]# /opt/lampp/lampp restart

Stopping XAMPP for Linux 1.6.4...

XAMPP: Stopping Apache with SSL...

XAMPP: Stopping MySQL...

XAMPP: Stopping ProFTPD...

XAMPP stopped.

Starting XAMPP for Linux 1.6.4...

XAMPP: Starting Apache with SSL (and PHP5)...

XAMPP: Starting MySQL...

XAMPP: Starting ProFTPD...

XAMPP for Linux started.

稍等就行了。

5.部分代码指导:

echo "

";

$i=$row['id'];//数据库表insun4中的id列,为了。。。。

echo "

".$row['title']."";

//echo "

".$row['title']."";

//echo "

".$row['description']."";

echo "

".$row['description']."";

echo "

";

?>

include 'config.php';

set_time_limit(0);//防止超时显示错误。

mysql_query("set names'gbk'");//utf8

//$url = "http://www.jj59.com/";

$gid = $_GET['id'];

$query="select * from insun4 where id = $gid" ;//用like选择性输出。where link like'http://www.jj59.com/yuanchuang/%'

//echo  $query;

$queryresult=mysql_query($query) or die("查询数据失败");//执行查询

//echo var_dump($queryresult);

while($row = mysql_fetch_array($queryresult)){

echo ($row['content'])."
";

}

?>

RewriteEngine On

RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2

RewriteRule ^(.*)/index.html$ $1/index.php

RewriteRule ^(.*)/wenzhang.html$ $1/wenzhang.php

RewriteRule ^(.*)/gushi.html$ $1/gushi.php

RewriteRule ^(.*)/sanwen.html$ $1/sanwen.php

RewriteRule ^(.*)/zawen.html$ $1/zawen.php

RewriteRule ^(.*)/shige.html$ $1/shige.php

RewriteRule ^(.*)/riji.html$ $1/riji.php

RewriteRule ^(.*)/xiaoshuo.html$ $1/xiaoshuo.php

RewriteRule ^(.*)/contact.html$ $1/contact.php

二,看到网上有2-3个方法,都是写个Url_rewrite函数,然后require的,感觉不好就不推荐大家了,大家可以去搜索下。

一般都是借助于apache,nginx,htaccess等,很少用php来实现url的静态化,用php来实现静态化比较麻烦。

如果出现下面这样,说明你没配置好。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值