PDA

View Full Version : Php伪静态页问题!


topvip
2009-01-05, 04:51 PM
果用PHP生成HTML那就难更新!

生成伪静态的话,用Apache的MOD Rewrite方法不太可靠,因为服务器不是我的,大多数服务器是别人的。有可能开有可能不开。

有可能 是LINUX也有可能是WIND。

那么我只有用别的方法找到了一个方法,来自互联网;
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;
}


我能看明白,但是我不知道如何调用!

比如讲我的网址:www.xxx.com/index.php

以上是首页,那么我访问www.xxx.com/xx-xx-xx.html这个时候没有 这个页面就会出错或者转向404页!

郁闷!我有点笨,不知道怎么写了。如果是:

www.xxx.com/index.php?xx-xx-xx.html这就太明显了!

请问有没有人做过?给个例子!谢谢!

topvip
2009-01-05, 04:52 PM
<?php
function mod_rewrite(){
global $_GET;
//$nav=$_SERVER["REQUEST_URI"];
$nav = '/129244/index.html';
//$script_name=$_SERVER["SCRIPT_NAME"];
$script_name = '/index.html';
$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;
}
$aa = mod_rewrite();
var_dump($aa);
echo '<br>';
var_dump($_SERVER["REQUEST_URI"]);
?>

这样看就明白了
发的那个函数只是对请求的url进行了分解,具体的操作还需要你根据你的url情况自己解决

topvip
2009-01-05, 04:53 PM
RewriteEngine On

# Rewrite requests for sitemap.xml

RewriteRule ^zzxj/sitemap.xml$ /zzxj/sitemap.php?target=google [L]

# Rewrite requests for urllist.txt
RewriteRule ^zzxj/urllist.txt$ /zzxj/sitemap.php?target=yahoo [L]


面的放在.htaccess里的,.htaccess放根目录
重写zzxj/sitemap.xml 至PHP程序