mod_rewrite + perl + mysql

Using a single web hosting account to host multiple sites

mod_rewrite + perl + mysql

Postby bugsys » Thu Aug 02, 2007 12:09 pm

Hi all,
I'm trying to force apache to ask mysql for each url. I use perl script, which accesses the database and depending on the DB querry returns: /index1.php?id=[DB_ROW] or /index2.php?... etc. mod_rewrite sends the querry and the perl script recives it properly, but for some reason it can't do mutch - even if {} else {} blocks don't actually work. expressions like "print '/blahblah/' . $uri . '/newblahblah/'" are printed in the rewrite.log like '/newblahblah/$uri' or even more interesting '/newblahblah/blahblah/$uri' ( $uri is ofcourse the correct string replaced. ) The most "complex" expression that I managed to get working is something like s/^\//%/; s/$/%/;

my httpd.conf without some RewriteCond has in it's <VirtualHost>:

RewriteEngine On
RewriteLog /var/log/rewrite.log
RewriteLogLevel 9
RewriteMap iwct prg:/usr/local/etc/apache2/mod_rewrite.pl
RewriteRule (.*) ${iwct:$1} [PT]

My Perl script is allmost this:

$| = 1;
while (<STDIN>){
$uri=$_;
s/^\//%/;
s/$/%/;
$string=$_;
$sthi->execute($string) or die "$DBI::errstr\n";
$index=$sthi->fetchrow_array();
$sthp->execute($string, $string) or die "$DBI::errstr\n";
$page=$sthp->fetchrow_array();
if ($index){
print '/index.php?source='.$index;
}
else {
if ($page){
print '/page.php?id='.$page;
}
else {
print $uri;
}
}
}

$sthi and $sthp are defined at the beginning of the script.
It works perfectly when started from the console, but not from within mod_rewrite.

I can't find where should the perl script output any errors too ...

Thanks for any help in advance.

P.S. Sorry for the bad englesh.

P.S.2: How does mod_rewrite work with DBM files ? Do I have to restart apache each time I update my DBM file ?
bugsys
 
Posts: 2
Joined: Thu Aug 02, 2007 11:46 am

Postby richardk » Sat Aug 04, 2007 12:45 pm

Try
Code: Select all
RewriteEngine On

RewriteLogLevel 9
RewriteLog /var/log/rewrite.log

RewriteMap iwct prg:/usr/local/etc/apache2/mod_rewrite.pl

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.*)$ ${iwct:$1} [PT,L]


How does mod_rewrite work with DBM files ? Do I have to restart apache each time I update my DBM file ?

No. It reads it when it changes.
Note
For plain text and DBM format files the looked-up keys are cached in-core until the mtime of the mapfile changes or the server does a restart. This way you can have map-functions in rules which are used for every request. This is no problem, because the external lookup only happens once!
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

thanks

Postby bugsys » Thu Aug 09, 2007 1:39 pm

Thanks, it did'nt help, because it seems the problem is in the way the perl script is executed ( perhaps the rights it has or who knows ) But the DBM file is actually a better way to go. It's sure enough faster and needs les resources. This week I have quite a lot to do, but next week I hope I'll find some time to play with it and make some experiments.
Thanks again for the fast responce
bugsys
 
Posts: 2
Joined: Thu Aug 02, 2007 11:46 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 83 guests

cron