Hello, im starting mad with this problem:
I would like to redirect the users from the page [B][url]http://www.mysite.com/team.php?id=12[B]http:[url]www.mysite.com/nameteam
to do this I have changed th httpd file of Apache adding this code:
[B]
[CODE]RewriteMap team prg:/home/www/web/include/userdir.php
RewriteRule ^/team/(.*)$ /team.php?id=${team:$1} [L,R]
[/B]
the userdir.php is a prg in php which read from a mysql table the nameteam from the id.
This is the code:
[code=php]#!/usr/local/web/php/bin/php
<?php
$fdin=fopen(“php://stdin”,”r”);
$fdout=fopen(“php://stdout”,”w”);
set_file_buffer($fdout,0);
while($l=fgets($fdin)) {
fputs($fdout,key_lookup($l));
}
function key_lookup($key) {
$hostname_conn_ht = “localhost”;
$database_conn_ht = “db”;
$username_conn_ht = “dbuser”;
$password_conn_ht = “secret”;
$conn_ht = mysql_pconnect($hostname_conn_ht, $username_conn_ht, $password_conn_ht) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_conn_ht, $conn_ht);
$query_rec = sprintf(“SELECT id FROM `user` WHERE team = ‘%s'”, $key);
$rec = mysql_query($query_rec, $conn_ht) or die(mysql_error());
$row_rec = mysql_fetch_assoc($rec);
$totalRows_rec = mysql_num_rows($rec);
if ($totalRows_rec>0) return $row_rec[‘id’];
else return $key;
mysql_free_result($rec);
}
?>
But it dos’nt works!
If I try to join [url]www.mysite.com/mynameteam
I can loo the URL change in [url]www.mysite.com/team.php?id=mynameteam
instead of [url]www.mysite.com/team.php?id=12
This seem becouse $totalRows_rec = 0 but i m sure “mynameteam” is in the db! Infact i have tryed cahnging the query in
[CODE]sprintf (SELECT id FROM `user` WHERE team = ‘%s'”, “mynameteam”)
and it is working.
A secondary Question:
I know the RewriteRule is it wrong and i would like to change it when i ll resolve the php problem, I don’t want the users will see the URL change. How i have to change this to redirect without change the URL in the window ?
Thanks! A lot for your time!