title: Configuring mod_rewrite and mod_jk for Apache 2.2 and JBoss 4.2.3
body: <p>My problem is as follows: I have JBoss 4.2.3 application server with AJP 1.3 connector running on one host under Windows (192.168.1.2 for my test environment) and Apache 2.2.14 running on another FreeBSD box (192.168.1.10). Apache acts as a "front gate" for all requests and sends them to JBoss via mod_jk. Everything was working fine until I had to do some SEO optimizations. These optimizations include SEF urls, so i decided to use mod_rewrite for Apache to alter requests before they are sent to JBoss. Basically, I nedd to implement 2 rules:</p>
  
  <ul>
  <li>Redirect old rules like "<a href="http://hostname/directory/" rel="nofollow noreferrer">http://hostname/directory/</a><em>" to "<a href="http://hostname/" rel="nofollow noreferrer">http://hostname/</a></em>" with permanent redirect</li>
  <li>Forward urls like "<a href="http://hostname/wtf/123/" rel="nofollow noreferrer">http://hostname/wtf/123/</a>" to "<a href="http://hostname/wtf/view.htm?id=123" rel="nofollow noreferrer">http://hostname/wtf/view.htm?id=123</a>" so that end user doesn't see the "ugly" URL (the actual rewrite).</li>
  </ul>
  
  <p>Here is my Apache config for test virtual host:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
  ServerAdmin webmaster@dummy-host.example.com
  DocumentRoot "/usr/local/www/dummy"
  ServerName 192.168.1.10
  
  &lt;IfModule mod_rewrite.c&gt;
  
      RewriteEngine On
  
      RewriteRule /directory/(.*) /$1 [R=permanent,L]
      RewriteRule ^/([^/]+)/([0-9]+)/?$   /$1/view.htm?id=$2
  
  &lt;/IfModule&gt;
  
  JkMount     /*      jsp-hostname
  
  ErrorLog "/var/log/dummy-host.example.com-error_log"
  CustomLog "/var/log/dummy-host.example.com-access_log" common
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>The problem is that second rewrite rule doesn't work. Requests slip through to JBoss unchanged, so I get Tomcat 404 error. But if I add redirect flag to the second rule like</p>
  
  <pre><code>RewriteRule ^/([^/]+)/([0-9]+)/?$   /$1/view.htm?id=$2 [R,L]
  </code></pre>
  
  <p>it works like a charm. But redirect is not what I need here :) . I suspect that the problem is that requests are forwarded to the another host (192.168.1.2), but I really don't have any idea on how to make it work. Any help would be appreciated :)</p>