Forum Moderators: phranque
my httpd.conf script is :
RewriteEngine on
RewriteLogLevel 3
RewriteLog "/rewrite.log"
RewriteMap chmap prg:/check.pl
RewriteRule /sites.examples/(.*) ${chmap:$1} [NS,P]
and my perl file script is:
#!/usr/bin/perl
$¦=1;
# PERL MODULES
use Mysql;
# MYSQL CONFIG VARIABLES
$host = "localhost";
$database = "test";
$tablename = "rewrite";
$user = "#*$!xx";
$pw = "#*$!#*$!x";
# PERL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);
# SELECT DB
$connect->selectdb($database);
#print 'http://192.168.1.24/website/sites/0162/examples@examples.com/s_31324654646464/index.html';
while (my $in = <STDIN>){
# $_ -- This holds the requested url to rewrite
chomp($in);
my $myquery = 0;
my $execute = 0;
my $array = 0;
# DEFINE A MySQL QUERY
$myquery = "SELECT * FROM rewrite WHERE short = \"$in\"";
# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery);
@array = $execute->fetchrow;
print 'http://192.168.1.24/'.$array[1];
}
##EOF##
when i try to hit URL
[192.168.1.24...]
it never returns anything and keep trying to load
in log file i found this
192.168.1.10 - - [25/Jun/2008:22:08:12 +0500] [192.168.1.24/sid#877f398][rid#8b2bfc0/initial] (2) init rewrite engine with requested uri /sites.examples/helloworld
192.168.1.10 - - [25/Jun/2008:22:08:12 +0500] [192.168.1.24/sid#877f398][rid#8b2bfc0/initial] (3) applying pattern '/sites.examples/(.*)' to uri '/sites.examples/helloworld'
browser keep trying to load but nothing came up
on the other hand when i run this perl script on shell it runs well takes input and print the path and then listen for another input
could anyone please help me in this regard
Thanks
I would recommend simplifying the problem by breaking it into parts. For example, comment-out all of the database-access code in the script, and insert a line that PRINTs a fixed and valid URL return value. Then see if the RewriteMap always correctly rewrites to that fixed URL value. Then try using a simplified database lookup (Select) on a database with only the one fixed URL in it.
By breaking the problem down into simpler steps, it will probably be much easier to solve.
Also make use of the rewritelog, server access log, and server error log, and correlate the information you see in those files.
This might even be a permissions problem. If it is, your error log should tell you.
Jim
But be aware that one and only one instance of this script is invoked when the server is restarted, and it must continue to run until the next server restart.
Therefore, there must be no situation where the script can "die" and no context-independent variables or storage can be used -- That is, the script must be able to support many concurrent requests, and keep the data for each of them separate.
As suggested earlier, a good approach would be to simplify the script so it doesn't use the database, and use that simplified version for testing until you get it working for multiple requests.
Jim