I have 2 servers, Apache and Jboss. Using JKmount .war files are mounted and present a complex site.


JkMount /directory/* ajp13
Alias /directory /jboss/server/default/deploy/directory.war
<Directory  /jboss/server/default/deploy/directory.war>
  Order allow,deny
  allow from all
  Options -Indexes
<Directory  /jboss/server/default/deploy/directory.war/WEB-INF>
  deny from all

I would like to use mod_rewrite on the Apache side to alter the URLs returned by mod_jk.


RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^$
RewriteRule /.* http://server.example/redirect.html [R=301,L]

Currently the above code only affects the images returned by Apache and not the pages returned by mod_jk.

Is this possible? How is it done?

There is a similar question asked at StackOverFlow however given a choice if it is possible I would like to handle this internal to Apache and not alter the Jboss configuration.

The server is OpenSuse 11.1 and I suspect there maybe some module precedence order issues however I have not been able to confirm this.

Examples of URLs would be:


In this example the first URL is mounted in mod_jk using the directives listed in the config above and would NOT be re-written by mod_rewrite. The second URL is a normal directory in the Apache site and is rewritten correctly.

Thanks All


After a long search I have found the answer to this one.

The rewrite directive must be placed globally for the (virtual) host not in the or in a .htaccess. Apache appears not to actually parse those files as the files served out of mod_jk are not part of that structure; which makes sense if you think about it. It will however apply mod_rewrite rules that apply to the entire host.


sorry cant comment, Im new here ... can you give an example url which is returned from mod_jk. Looks like the regular expression doesn`t fit to the page returned.

Try to redirect all to http://server.example/redirect.html:

RewriteRule .* http://server.example/redirect.html [R=301,L]

If this works, its the regular expression, which troubles you.

Let me explain a little bit.

you have an URI which looks like: http://foo.bar.com/anything

Your regular expression (/.*) is now searching for a slash followed by something. But in the Uri, there is no / in "anything".

If you have an image: e.g.

http://foo.bar.com/images/image.png than there is an / in images/image.png and the regular expression matches and does the redirect.

If you want to redirect somesite to another Server:

http://foo.bar.com/somesite -> http://bar.foo.com use

RewriteRule somesite.* http://server.example/redirect.html [R=301,L]
  • Unfortunately this isn't a regex issue. I am bouncing every URL as that is my intention however URLs returned by mod_jk are not re-written; I suspect this may have something to do with the precedence of mod_rewrite vs mod_jk however I really don't have any evidence to back that up. Re-writes of image URLs are performed correctly and are in the same position as the index.jsp which is not re-written at all (but should be). – Antitribu Oct 20 '09 at 16:36
  • It could be a precendence issue. But you don´t give a concrete example of what you are trying to do. You say mod_jk generates an URL and it is not redirected. But if your regex is wrong, it would not be redirected at all, no matter if there is a precendence or not. So are you 100% sure it´s not the problem of your regular expression, or is it just a guess? – evildead Oct 20 '09 at 18:27
  • I am as certain as it is possible to be with these things is that it is not an issue with the regex; regardless of the expression used they do not affect URLs returned through mod_jk. Prior to posting I have tried a large number of regexs including your example. In all cases they affect URLs returned by apache but not those by mod_jk. For clarity I have added in example URLs. – Antitribu Oct 21 '09 at 8:50
  • Did you also tried the RewriteCondition thing? Maybe the precedence of the RewriteCondition is higher than the mod_jk thing. But thats just a guess. – evildead Oct 21 '09 at 23:44
  • The problem is mod_jk isn't affected by anything, you can put a Deny from All in the root of a directory with a mod_jk submount and it will still return the mod_jk pages. – Antitribu Oct 22 '09 at 8:53

Sorry, can't comment, but in response to your answer Antitribu, you could also put the rewrite statements in a <Location> context. There's a nice section of the apache manual that describes when to use <File>, <Location>, .htaccess, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.