A rule is a class that can match a request. It can also rewrite both incoming links to the proxy and outgoing links found in html.

All rules are specified by the attribute className.


This rule will always match and you might wonder why it is then needed. Well, if no rule is matched the server doesn't know where to send the specific request and will not return anything. Therefore you should always have an AcceptEverythingRule at the end.


There aren't any parameters for this rule


If you want to match on the clients IP so that e.g. only users from the internal network can access a page you can use the IPRule. This rule will check the IP for an incoming connection and see if it lies within the start range and end range. If the IP is in range we have a match.




The start of the IP range that we will allow connections from.



The end of the IP range.


This is a simple rule to match the current hour. This rule can be used when you only want to allow connections to a server during some hours of the day. The time is set with a 24h clock. E.g., 10 PM is set as 22. Midnight can be set as 0 or 24.




The hour of day when we will start to allow connections.



The last hour of day that connections will be allowed.

If endTime is earlier then startTime e.g., startTime=23 endTime=01 it will be interpreted as a time crossing a date barrier. It will work just as expected, connections made at 11:00 PM to 1:00 AM (the following day) will be allowed.


The DirectoryRule will check the start of the URL (excluding the context path where you are running the proxy). If the path starts with the directory specified in the XML there is a match. The directory will be removed from the URL before the request is sent to the server so that you can map a server to any directory without thinking about the server you are mapping.




This is the directory we are mapping to.


The DirectoryRule will check the start of the URL for a match and remove the directory before sending the request to the server. Sometimes you want a more powerful rewriting than this, this is the time you use the RewriteRule.

The rewrite rule will use regular expressions to try to match a URL. When the URL is matched you can also specify in what way it should be rewritten, changing the URL before the proxy connects to the server. This makes it possible to do some quite powerful operations, much like mod_rewrite or urlrewrite.




This is the regex we try to match.



When from was a match this is what the match will be rewritten to.


Required if you are using rewriting! This is the pattern to decide if any links found in the html should be rewritten.


Required if you are using rewriting! When revertFrom was a match this is what the match will be rewritten to.

One important issue is that when we are using rewriting revertFrom and revertTo must be the logical opposite of from and to. If they aren't opposites, links found in html that are rewritten wont be matched or at least not correctly rewritten by to. This means that links found in HTML that are rewritten wont work when the user tries to follow them.


The following example is the structured homedirs example taken from the mod_rewrite documentation. The regex and quote is taken from the mod_rewrite vs urlrewrite section in the urlrewrite manual.

Some sites with thousands of users usually use a structured homedir layout, i.e. each homedir is in a subdirectory which begins for instance with the first character of the username. So, /~foo/anypath is /home/f/foo/.www/anypath while /~bar/anypath is /home/b/bar/.www/anypath. We use the following ruleset to expand the tilde URLs into exactly the above layout.

<rule className="net.sf.j2ep.rules.RewriteRule" from="^/~(([a-z])[a-z0-9]+)(.*)" to="/home/$2/$1/.www$3" revertFrom="^/home/[a-z]/([a-z0-9]+)/.www(.*)$" revertTo="/~$1$2" />

This made it possible to present a very easy page syntax for the user that is followed to a more complex URL on the server side.


Some times you want to check for many things. Let's say we want a server to be mapped only when the directory is "/apache-wiki" and the user has IP 127.0.0.x. To make sure both of these rules are met we use a CompositeRule like the one below.

<composite-rule className="net.sf.j2ep.rules.CompositeRule"> <rule className="net.sf.j2ep.rules.DirectoryRule" directory="/apache-wiki" /> <rule className="net.sf.j2ep.rules.IPRule" startRange="" endRange="" /> </composite-rule>

Note that the CompositeRule uses the element composite-rule instead of the normal rule.

The CompositeRule contains many other rules. In order to have a match for a CompositeRule all of the included rules have to match. There are no specific parameters for the CompositeRule. Logo