2 Replies Latest reply on Oct 1, 2009 4:22 AM by jfclere

    rewritevalve substitution class with odd results

      I have 4.2.2 GA of JBoss Application Server that is using the rewritevalve from the web server. I also have a couple of custom RewriteMap classes and in one of them I am doing something similar to the vhost found within Apache's version of mod_rewrite. The only problem is that somehow the line from the rewrite properties isn't getting filled in correctly.

      Here is a snippet of my rewrite.properties file:

      #
      # define two maps: one for fixing the URL and one which defines the
      # available virtual hosts with their corresponding DocumentRoot.
      #
      RewriteMap lowercase custom.rewrite.ToCase lower
      RewriteMap vhost custom.rewrite.VHost c:/jboss422/conf/vhost.map
      #
      # 1. make sure we have a Host header, because currently our approach
      # only supports virtual hosting through this header
      #
      RewriteCond %{HTTP_HOST} !^$
      RewriteCond %{HTTP_HOST} !^null$
      #
      # 2. remove the :port value from the HTTP_HOST if it is there
      #
      RewriteCond %{HTTP_HOST} ^([^:]*).*$
      #
      # 3. lowercase the vanity name
      #
      # "%1" back-references to the last matched RewriteCond pattern
      #
      RewriteCond ${lowercase:%1|default.com} ^.*$
      #
      # 4. lookup this hostname in vhost.map and remember it
      #
      # "%1" back-references to the last matched RewriteCond pattern
      #
      RewriteCond ${vhost:%1} ^(/.*)$
      


      Everything works great up until the the RewriteCond line using the lowercase map. The %1 should get replaced by the result from the previous RewriteCond, but it doesn't. It actually goes through where the key in the custom RewriteMap class is actually "%1", minus the quotes.

      I also tried a line like the following:

      RewriteCond ${lowercase:%{HTTP_HOST}|default.com} ^.*$
      


      But that even through a weird error from line 158 in the Substition.parse class and method. It shouldn't even have been in there as there was both a '$' and a '%' in the line.

      I have System.err.println statements in the custom RewriteMap and it is reading the vhost.map file correctly, but the key isn't correct.

      Any ideas?


        • 1. Re: rewritevalve substitution class with odd results
          sancheski

          Hello,

          I am trying to do the same using rewrite valve in jboss 4.2.3. As far as I have checked the source code, it is impossible to use a RewriteMap through a variable key (let say %{REQUEST_URI} or any other). Example of the syntax:

          RewriteMap urlsMap com.UrlsRewriteMap testFile
          RewriteCond ${urlsMap:%{REQUEST_URI}|default} !default
          ....
          

          So if it is not possible to use variable keys, does it make any sense using a RewriteMap? When does it make sense?

          This feature would be very usefull as url rewriting rules could be writing dinamically.

          Thanks in advance,

          David Sancho

          • 2. Re: rewritevalve substitution class with odd results
            jfclere

            What do you want to do?