url 静态化是一个利于搜索引擎的设置,通过 url 静态化,达到原来是动态的 php 页面转换为静态化的 html 页面,
当然,这里的静态化是一种假静态,目的只是提高搜索引擎的搜索量
apache 服务器下配置 url 静态化的 rewrite 规则:
apache 2.x 的用户请检查 conf/httpd.conf 中是否存在如下一段代码:
loadmodule rewrite_module modules/mod_rewrite.so
在conf/httpd.conf配置中加入 如:
rewriteengine on
rewriterule ^(.*)/archiver/((fid|tid)-[/w/-]+/.html)$ $1/archiver/index.php?$2
rewriterule ^(.*)/forum-([0-9]+)-([0-9]+)/.html$ $1/forumdisplay.php?fid=$2&page=$3
rewriterule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)/.html$ $1/viewthread.php?tid=$2&extra=page/%3d$4&page=$3
rewriterule ^(.*)/space-(username|uid)-(.+)/.html$ $1/space.php?$2=$3
rewriterule ^(.*)/tag-(.+)/.html$ $1/tag.php?name=$2
案例说明:
rewriterule /products/([0-9]+) /fancy/products.php?id=$1
当你在浏览器地址栏输入 http://www.mysite.com/product/123 时,这个地址被重写为 http://www.mysite.com/fancy/product.php?id=123
rewrite规则表达式的说明:
. 匹配任何单字符
[chars] 匹配字符串:chars
[^chars] 不匹配字符串:chars
text1|text2 可选择的字符串:text1或text2
? 匹配0到1个字符
* 匹配0到多个字符
+ 匹配1到多个字符
^ 字符串开始标志
$ 字符串结束标志
/n 转义符标志