apache - Can I use multiple results from MySQL query in Apache2 mod_rewrite? -
i trying control access apache2 mod_rewrite. want allow ips accessing site.
i understand can use file such
rewritemap hosts-allow "txt:/path/to/hosts.txt"
and have read can use sql query, apparently works 1 result , if multiple rows returned uses random one. there way use multiple results?
otherwise, have automate saving ips mysql file myself use multiple results?
if yes apache2 automatically flush cache of file whenever changes?
any insights welcome, :)
i got work.
if have similiar problem apache2 file 000-default.conf (look location of file on linux distro) has this.
<virtualhost *:80> dbdriver mysql dbdparams "host=localhost,user=root,pass=password,dbname=name" rewritemap whitelist "dbd:select ip users ip = %h limit 1" <directory /var/www> rewriteengine on rewritecond "${whitelist:%{remote_addr}|found}" "found" rewriterule "^" "" [f] </directory> ... </virtualhost>
now explain bit
rewritemap whitelist "dbd:select ip users ip = %h"
parameter %h in here stands ip address of request, doesn't use multiple results sql query, since return rows when it's condition met can work amount of ip's.
rewritecond "${whitelist:%{remote_addr}|found}" "found"
the :%{remote_addr} searches remote_addr in whitelist, contain ip address when found sql query, otherwise it's empty.
rewriterule "^" "" [f]
here [f] means forbidden, can set example [r] redirect, have more information on how use it, , "^" means rule being applied urls.
the empty "" key delimeter (?) apache2 expects in .txt maps, since use sql query got none in here.
if want use mod_dbd mysql have install package (for example on debian 8)
sudo apt-get install libaprutil1-dbd-mysql
or otherwise apache2 won't start start after setting dbdriver mysql
you have enable mod_rewrite , mod_dbd in apache2 with
a2enmod rewrite a2enmod dbd
hope helpful :)
Comments
Post a Comment