為了不在地址欄里暴露過多的信息,想到了做一個(gè)地址的隱藏,在網(wǎng)上找了一些資料,決定試試UrlRewriet
在網(wǎng)上下載了
urlrewrite的包,我下載的是urlrewritefilter-2.6-src.zip
打開壓縮包,將里面的urlrewrite-2.6.0.jar放在工程的/WEB-INF/lib/目錄下
將里面的urlrewrite.xml放在工程的/WEB-INF/目錄下
修改/WEB-INF/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>
在urlrewrite.xml里加入規(guī)則,如:
<rule>
<note>
The rule means that requests to /page/pagea.html will be redirected to /pagea.jsp
</note>
<from>/html/([a-z]+).html</from>
<to>/$1.jsp</to>
</rule>
此時(shí)在瀏覽器里訪問/html/pagea.html會(huì)顯示/pagea.jsp的內(nèi)容,OK,搞定
如果這種地址隱藏可行,那么可以把jsp頁(yè)面?zhèn)窝b成asp或是php頁(yè)面,改寫規(guī)則如下
<rule>
<note>
The rule means that requests to /html/pagea.html will be redirected to /pagea.jsp
</note>
<from>/html/([a-z]+).html</from>
<to>/$1.jsp</to>
</rule>
<rule>
<note>
The rule means that requests to /asp/pagea.asp will be redirected to /pagea.jsp
</note>
<from>/asp/([a-z]+).asp</from>
<to>/$1.jsp</to>
</rule>
<rule>
<note>
The rule means that requests to /php/pagea.php will be redirected to /pagea.jsp
</note>
<from>/php/([a-z]+).php</from>
<to>/$1.jsp</to>
</rule>
此時(shí),在瀏覽器里輸入
/html/pagea.html
/asp/pagea.asp
/php/pagea.php
均可以訪問頁(yè)面pagea.jsp
幾個(gè)月前我寫了一篇筆記做地址偽裝的,看來完全可以用這個(gè)東東代替了,上次寫的那個(gè)還有一些問題沒有完全解決,用urlrewrite做地址隱藏,真是感覺很專業(yè),完美呀,初次使用,可能有些高級(jí)的功能還沒有用到,不過通過這樣的試驗(yàn),已感覺出它的強(qiáng)大,這應(yīng)該是一個(gè)很好的解決方案.