您的位置:首页 > 其它

巧用404实现真静态

2016-04-01 00:00 225 查看
摘要: 工作中遇到真静态问题。自己解决方案

巧用404生实现真静态

Apache配置

<VirtualHost *:80>

ServerName test.com

DocumentRoot "D:\wamp\web\test"

DirectoryIndex index.html index.php

ErrorDocument 404 /404/404show.php

ErrorLog "logs/test.com"

CustomLog "logs/test.com" common

</VirtualHost>

1:将404页面指向一个php文件

404show.php大致类容

$_SERVER["REQUEST_URI"] = str_replace( "//","/",$_SERVER["REQUEST_URI"]);
$webFileArray = explode("/",$_SERVER["REQUEST_URI"]);
switch ($webFileArray[1])
{
case "news":
{
//     url中含有news处理逻辑
}
break;

case "postion":
{
//     url中含有postion处理逻辑
}
break;

default:
header("HTTP/1.0 404 Not Found");
header("Location: /404/404.htm");
break;
}

假如访问www.test.com/news/1.html

若1.html不存在,则访问404show.php页面,走url中含有news处理逻辑,可用于查看数据库是否有数据,若有,则生成静态文件,没有则访问真正的404.页面。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: