Wildfly 和第三方 UrlRewrite

资源

UrlRewrite概念可参考: http://blog.csdn.net/crazy1235/article/details/8585310

UrlRewrite第三方库: http://tuckey.org/urlrewrite/

WildFly下载: http://wildfly.org/downloads/

安装及相关配置

  1. Ubuntu下完成WildFly下载后执行"unzip wildfly-10.1.0.Final.zip"解压WildFly到当前目录,完成此步骤后可以根据需要移动WildFly到其他指定目录,并可修改目录名称比如"wildfly10".
  2. 进入"./wildfly/bin"并执行"add-user.sh"添加新用户,比如"admin",这个过程指定用户角色并不重要.
  3. 完成用户注册后,执行"standalone.sh"启动WildFly Application Server.
  4. 服务器启动后,缺省情况下访问:http://localhost:9990部署Web App,完成部署的应用从 http://localhost:8080访问.

"WEB-INF/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>

要使用第三方UrlRewrite库则需要把"urlrewritefilter-4.0.3.jar"拷贝到Web App的"WEB-INF/lib",然后在"WEB-INF"下添加如下jboss-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
 <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
  http://www.jboss.com/xml/ns/javaee
  http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
  <context-root>/</context-root>
 </jboss-web>

UrlRewrite规则定义在如下"WEB-INF/urlrewrite.xml"文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"  
"http://tuckey.org/res/dtds/urlrewrite2.6.dtd">  
<urlrewrite>  
    <rule>  
        <from>/hello/abc/</from>  
        <to type="forward">/</to>  
    </rule>
    <rule>  
        <from>/hallo/</from>  
        <to type="forward">/</to>  
    </rule>
</urlrewrite>

完成部署和相关配置后,可以通过以下Urls访问部署的Web App:

http://localhost:8080/

http://localhost:8080/hello/abc/

http://localhost:8080/hallo/

  

      

 

posted @ 2017-09-13 11:56  Jinzd  阅读(147)  评论(0编辑  收藏  举报