巧用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大致类容
假如访问www.test.com/news/1.html
若1.html不存在,则访问404show.php页面,走url中含有news处理逻辑,可用于查看数据库是否有数据,若有,则生成静态文件,没有则访问真正的404.页面。
巧用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.页面。
相关文章推荐
- servletContext.getContextPath()不存在
- Apache shiro登录成功后跳转到访问被拦截之前的路径
- extjs
- R语言从入门到精通(干货整理)
- 看了这个,让你从一个wordpress门外汉变成小专家!
- php的命名空间
- 天下数据教你挑选最稳定的服务器
- KeyMob:为国内应用开发者管理的广告聚合平台
- KeyMob探索移动广告聚合平台
- KeyMob广告聚合平台致力于提升开发者收入
- 国内最稳定的移动广告聚合平台|KeyMob
- KeyMob移动广告聚合平台让开发者收入更高
- IOS博客项目搭建-09-OAuth02授权
- 微服务架构的优势与不足(及与SOA区别)
- 领域驱动设计系列(2)浅析VO、DTO、DO、PO的概念、区别和用处
- JVM内存管理和垃圾回收
- mysql高级运维dba要掌握的九大工具链
- pl/sql导入excel到oracle表
- 验证上传文件格式问题
- Tomcat 内存设置