URL的静态化对SEO是非常友好的。有很多网站40%左右的流量都是来源于搜索引擎,特别是新网站。
动态URL:/common/detail.html?id=268789
静态URL:/common/detail-268789
一种方法:可以在apache或nginx中做配置。
二种方法:可以在sturts中处理
1、下载urlrewritefilter-3.1.0.zip,附件中有。
2、解压后,将urlrewrite-3.1.0.jar放入 WEB-INF/lib,将urlrewrite.xml放入WEB-INF/
3、在web.xml中加入
<filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <init-param> <param-name>logLevel</param-name> <param-value>WARN</param-value> </init-param> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.html</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>
urlRewrite的filter要在struts之上
4、urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN" "http://tuckey.org/res/dtds/urlrewrite3.1.dtd"> <!-- Configuration file for UrlRewriteFilter http://tuckey.org/urlrewrite/ --> <urlrewrite> <rule> <note> The rule means that requests to /test/status/ will be redirected to /rewrite-status the url will be rewritten. </note> <from>/common/detail\-([0-9]+)$</from> <to>%{context-path}/common/detail.html?id=$1</to> </rule> </urlrewrite>
from是接到的请求url,to是解晰后的动态url。都是正则,原文件中有详细的使用介绍。
这时可以访问/common/detail-268789试试效果