服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

its-cms 2.0 url设计构想

我这次重做cms,准备所有的链接按照下面方式作


http://localhost/index.html

http://localhost/cms/news/index.html  列出所有新闻
http://localhost/cms/news/index1.html 翻页
http://localhost/cms/news/20060410/n000000001.html 列出具体一条

http://localhost/cms/news/xjxjynews/index.html 可以继续往下加

http://localhost/cms/xxjj/index.html
http://localhost/cms/xxjj/xxld/index.html
http://localhost/cms/xxjj/xxld/about.html

整个节点按树状延生
所有/cms的下面都被拦截,然后根据uri调用相应模板
也就说/cms下面的路径都是虚假的,都不是服务器上的实际路径
而且这样的链接便于被搜索。便于用squid作前置缓存。便于隐藏实际后台实现
统一的入口也便于预防黑客攻击,防止例如 ../.。 或者 sql注入

如果使用php,实现的方法是使用url复写

# begin itscms restrictions
rewriteengine on
rewritebase /itscms
rewriterule cms/.*?/.html cms.php
# end itscms restrictions

然后解析url

function get_url_params( $base_url)
{
  $request = substr( $_server['request_uri'], strlen( $base_url));

  if( substr( $request, -1) == '/')
    $request = substr( $request, 0, -1);

  return explode( '/', $request);
}

 

如果用java实现

用/cms/* 实际上是转到servlet
使用 httpservletrequest req
string pathinfo = req.getpathinfo() ;

然后解析路径

扫描关注微信公众号