Saturday, March 26, 2011

Enabling URL rewriting in JBoss

This isn't particularly difficult, but the information contained in JBoss docs is pretty vague. Basically to enable URL rewrites, you need to create a "context.xml" file and place it inside the WEB-INF -directory of your web app. In the context file, enable the rewrite valve as follows:

<context cookies="true" crosscontext="true">
    <valve classname="org.jboss.web.rewrite.RewriteValve">

Next, create a "rewrite.propreties" file and place it in the same directory. Add your rewrite rules there.
Nothing more to it really. The syntax is the same as in Apache's mod_rewrite, but JBoss doesn't support every feature there, at least I found that the RewriteLog directive is not supported.

Note that when you add or edit a rule, you need to restart your web app for it to take effect.

If you find that your rules are not working, its propably because your rule is wrong, not that the rewrites are not enabled. If you specify a rule with incorrect syntax you will get an exception in the JBoss console/server log when you (re)start your web app. Make very simple test rule and verify that it works, then start making it more complex and building up from that.

No comments:

Post a Comment