3

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

eg:

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>
<Directory  /jboss/server/default/deploy/directory.war/WEB-INF>
  deny from all
</Directory>

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

eg:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^192.168.1.1$
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:

http://site.example/directory/index.jsp
http://site.example/foo/other.html

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

Antitribu
  • 1,739

3 Answers3

2

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.

Antitribu
  • 1,739
1

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]
evildead
  • 892
0

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.

pra
  • 642