Posted on 2009-01-16 09:50
ZhouFeng 閱讀(343)
評論(0) 編輯 收藏 所屬分類:
原創 、
Web開發 、
Web服務器
為了不在地址欄里暴露過多的信息,想到了做一個地址的隱藏,在網上找了一些資料,決定試試UrlRewriet
在網上下載了
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里加入規則,如:
<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>
此時在瀏覽器里訪問/html/pagea.html會顯示/pagea.jsp的內容,OK,搞定
如果這種地址隱藏可行,那么可以把jsp頁面偽裝成asp或是php頁面,改寫規則如下
<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>
此時,在瀏覽器里輸入
/html/pagea.html
/asp/pagea.asp
/php/pagea.php
均可以訪問頁面pagea.jsp
幾個月前我寫了一篇筆記做地址偽裝的,看來完全可以用這個東東代替了,上次寫的那個還有一些問題沒有完全解決,用urlrewrite做地址隱藏,真是感覺很專業,完美呀,初次使用,可能有些高級的功能還沒有用到,不過通過這樣的試驗,已感覺出它的強大,這應該是一個很好的解決方案.