How to Rewrite URLs with the Rewrite Valve of JBoss Web

Engine

1) Add the following to the <Install Dir>/server/default/deploy/jbossweb.sar/server.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Server>
  ...
  <Service>
    ...
    <Engine name="jboss.web">
      ...
      <Valve className="org.jboss.web.rewrite.RewriteValve" />
    </Engine>
  </Service>
</Server>

2) Create the rewrite.properties file in either the <Install Dir>/server/default/conf or <Install Dir>/server/default/deploy/jbossweb.sar/localhost file:

# Rewrite URLs like "http://localhost/rewritesample/sample/Hello%20World!" to "http://localhost/rewritesample/sample?msg=Hello%20World!"
RewriteRule ^/rewritesample/sample/(.*) /rewritesample/sample?msg=$1

3) Restart JBoss Web.

Host

1) Add the following to the <Install Dir>/server/default/deploy/jbossweb.sar/server.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Server>
  ...
  <Service>
    ...
    <Engine name="jboss.web">
      ...
      <Host name="localhost">
        ...
        <Valve className="org.jboss.web.rewrite.RewriteValve" />
      </Host>
    </Engine>
  </Service>
</Server>

2) Create the rewrite.properties file in either the <Install Dir>/server/default/conf or <Install Dir>/server/default/deploy/jbossweb.sar/jboss.web/localhost file:

# Rewrite URLs like "http://localhost/rewritesample/sample/Hello%20World!" to "http://localhost/rewritesample/sample?msg=Hello%20World!"
RewriteRule ^/rewritesample/sample/(.*) /rewritesample/sample?msg=$1

3) Restart JBoss Web.

Context

1) Create a WEB-INF/context.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Valve className="org.jboss.web.rewrite.RewriteValve" />
</Context>

2) Create the WEB-INF/rewrite.properties file:

# Rewrite URLs like "http://localhost/rewritesample/sample/Hello%20World!" to "http://localhost/rewritesample/sample?msg=Hello%20World!"
RewriteRule ^/sample/(.*) /sample?msg=$1

3) Deploy the app.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s