seo優化urlrewrite僞靜態技術

1.下載urlrewrite-3.2.0.jarhtml

2.在WEB-INF下增長urlrewrite.xmlweb

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://tuckey.org/res/dtds/urlrewrite3.2.dtd">

<urlrewrite>

    <!-- <a href="projects/" >z轉換</a> 代碼實際去訪問/projects/item.jsp-->
    <rule>
        <from>^/projects/$</from>
        <to type="forward">/projects/item.jsp</to>
    </rule>


    <rule>
        <from>^/articles/$</from>
        <to type="forward">/articles/member_atr.jsp</to>
    </rule>
    
<!-- $1表示第一個正則表達式 $2-表示第2個->
    <rule>
        <from>^/articles/a-([0-9]+)\.html$</from>
        <to type="forward">/articles/member_atrdetail.jsp?id=$1</to>
    </rule>

    <rule>
        <note>
            將全部.jsp文件映射爲.htm
        </note>
        <from>^/([_a-zA-Z]+[_0-9a-zA-Z-/]*[_0-9a-zA-Z]+).htm$</from>
        <to type="forward">/$1.jsp</to>
    </rule>
</urlrewrite>

 

3.web.xml中配置正則表達式

<filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
相關文章
相關標籤/搜索