Received: (qmail 32488 invoked by uid 501); 30 Dec 2001 13:16:00 -0000 Message-Id: <20011230131600.32487.qmail@apache.org> Date: 30 Dec 2001 13:16:00 -0000 From: Regis Grison Reply-To: regis@grison.org To: submit@bugz.apache.org Subject: [PATCH] mysql in mod_rewrite X-Send-Pr-Version: 3.110 >Number: 9318 >Category: mod_rewrite >Synopsis: [PATCH] mysql in mod_rewrite >Confidential: no >Severity: non-critical >Priority: medium >Responsible: apache >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: apache >Arrival-Date: Sun Dec 30 05:20:00 PST 2001 >Closed-Date: >Last-Modified: >Originator: regis@grison.org >Release: 1.3.22 >Organization: apache >Environment: Linux mensmagna 2.4.6 #9 Sat Nov 17 11:40:07 CET 2001 i686 unknown What's mising ? Debian, Duron 650, 384Mo, connection : 128kb gcc : gcc version 2.95.4 20011006 (Debian prerelease) >Description: Hello, I needed for my work to have mod_rewrite to look in mysql database so I made a patch (the very first one I send, so tell me if I made a mistake). To apply this patch, "patch -p0 < mod_rewrite-mysql.patch" in the src/modules/standard/ directory seems to work (after un-gzip), but I'm not so familiar with that. Here is what I added : My new RewriteMap directive now support mysql as a type of map, the file specified after the ':' is a config file that may be like that (in RewriteMap txt format) : server mysqlserver.mydomain.org port 3306 user mylogin passwd mypassword base mydatabasename select select an_entry from mytable where myarg='$1' and mysecondarg like '$1%' Note that port is optionnal (defaults to 3306) and select may have any number of $1. The $1 will be replaced by the key value (and it should be easy to change to something else if you prefer). If more than one entry is to be returned by mysql, only the first one will be return by RewriteMap. This is quite flexible because you can use several tables and anything after "where", keeping in mind that $1 will be the arg in httpd.conf RewriteRule. For example : RewriteMap mysqltest mysql:/path/to/myfile RewriteRule ^/something$ ${mysqltest:azerty} Will do this request : select an_entry from mytable where myarg='azerty' and mysecondarg like 'azerty%' I hope I've done a clean work (I used the same structure that txt type, including pool and cache). I make as little changes as I could outside a NO_MYSQL_REWRITEMAP define. I am just starting to test it for real and I'll contact you if I find anything but the code seems to work well. I made one other change : I needed the subdomain name (like SERVER_NAME but without the ending mydomain.com), I added it, called SUBDOMAIN_NAME, there is no relation beetween the to patches but as it is a simple change with a few lines in the same file, I let it in this patch. I let some comments in the code, hope it will help. I think I will put this code in a web page in a few days. I can give you an URL later if you wish. Hope I forgot nothing. Have a good day. Regis. >How-To-Repeat: >Fix: that's done :) >Release-Note: >Audit-Trail: >Unformatted: [In order for any reply to be added to the PR database, you need] [to include in the Cc line and make sure the] [subject line starts with the report component and number, with ] [or without any 'Re:' prefixes (such as "general/1098:" or ] ["Re: general/1098:"). If the subject doesn't match this ] [pattern, your message will be misfiled and ignored. The ] ["apbugs" address is not added to the Cc line of messages from ] [the database automatically because of the potential for mail ] [loops. If you do not include this Cc, your reply may be ig- ] [nored unless you are responding to an explicit request from a ] [developer. Reply only with text; DO NOT SEND ATTACHMENTS! ]