title: MySQL + htaccess mod_rewrite?
body: <p>I'm using a proxy-like short domain in conjunction with my site. The short domain is hrci.me and the long domain is reachchallenges.infectionist.com. hrci.me uses mod_rewrite and has a rule that pretty much does a simple redirect from hrci.me to reachchallenges.infectionist.com, so for example:</p>
  
  <pre><code>hrci.me/x/y.php
  </code></pre>
  
  <p>would redirect to</p>
  
  <pre><code>reachchallenges.infectionist.com/x/y.php
  </code></pre>
  
  <p>Simple as can be. On the main site I have more rules that further rewrite the URL, prettifying it. One example is a script on my site, challenges.php, which accepts a single parameter, <em>chid</em>, which is the challenge ID linked to more information in the database. Passed as a parameterized script it would look like this: <code>/challenge.php?chid=123</code>, but after it's rewritten it looks like this: <code>/challenge/123/Challenge+Title/</code>, where <code>Challenge+Title</code> is the actual title of the item from the database.  There's also a different way you can call the same page, like this: <code>/ch123</code>, so in essence you can access the page 3 different ways:</p>
  
  <pre><code>1. /challenge.php?chid=123
  2. /challenge/123/Challenge+Title/
  3. /ch123
  </code></pre>
  
  <p>This actually works perfectly, the issue that I have is that I want the URLs that are redirected from hrci.me to first be rewritten to look like #2 above, so the user would click hrci.me/ch123 and the htaccess file would read the database, get the title for challenge id 123, rewrite the url to <code>/challenge/123/Challenge+Title/</code> and then redirect it to reachchallenges.infectionist.com. Is something like this possible?  Is it possible to read from a MySQL database using htaccess in this way?</p>
  
  <p><strong>UPDATE</strong>:
  I added this to my httpd.conf file:</p>
  
  <pre><code>DBDriver mysql
  DBDParams "host=*****,user=*****,pass=*****,dbname=*****"
  RewriteMap hrci "dbd:SELECT title FROM challenges WHERE id = %s"
  RewriteLog "/home/halo2freeek/rewrite.log"
  RewriteLogLevel 3
  </code></pre>
  
  <p>Then added a RewriteRule to one of my subdomains that I don't really use (to test it):</p>
  
  <pre><code>RewriteEngine On
  RewriteRule ^ch([0-9]{1,4})(/)?$ http://reachchallenges.infectionist.com/challenge/$1/${hrci:$1} [R=301,L]
  </code></pre>
  
  <p>When I visit this path on the subdomain:</p>
  
  <p>/ch232</p>
  
  <p>It should redirect to:</p>
  
  <p><a href="http://reachchallenges.infectionist.com/challenge/232/Challenge+Title" rel="nofollow">http://reachchallenges.infectionist.com/challenge/232/Challenge+Title</a></p>
  
  <p>But instead it redirects to:</p>
  
  <p><a href="http://reachchallenges.infectionist.com/challenge/232/" rel="nofollow">http://reachchallenges.infectionist.com/challenge/232/</a></p>
  
  <p>Without the title. Am I doing something wrong?  Do I have to specify <code>RewriteEngine On</code> in the httpd.conf file?</p>
  
  <p><strong>UPDATE 2</strong>: Ok, so I added the <code>RewriteEngine On</code> line and saved, when I tried to restart Apache I got this error:</p>
  
  <pre><code>RewriteMap: file for map hrci not found:/dh/apache2/apache2-ps54462/dbd:SELECT title FROM challenges WHERE id = %s
  </code></pre>
  
  <p>It looks like it's completely ignoring the <code>dbd</code> part and trying to read the whole thing as a file name. Now I really don't know what I'm doing wrong.</p>