Forum Moderators: phranque
I m a noob with a noob question, i have studied all days and I m near to the solution but i need your help!
I have a website where my users have a public page at the url:
http://www.website.com/name.php?id=xx where xx is the id in the mysql DB
I would like a redirect to a more simple url:
http://www.website.com/nameofuser So I have created a REWRITEMAP to a php prg that return the nameofuser starting from the id (I'm cool! I made it myself!). And it is working fine!
in the .htaccess i have wrote:
RewriteEngine On
RewriteMap team prg:/home/www/web/include/userdir.php
RewriteCond %{HTTP_HOST} ^([^:]+)
RewriteRule ^/([^/\.]+)/?$ /team.php?id=${team:$1} [R]
And it seem to work too! But only first time after the restarting of apache...
so if i retstart the server and then i go to the url:
www.website.com/myteam I have made a lot of test and now I m really confused! I dont undestand if it is a probelm of the rewrite rule or i have a mistake in the prg php.
Can someone help me ?
I have another (noob) question about the rewriterule, in the exemple above I see the url to change, but if i don't want it i take off the [R], I have a redirect but the URL is the same, thi is good apart...that every element in the page is missing! Missing link, missing img etc... I suppose i have to correct the Rule but at moment I m very confused!
Thank for your help!
If I boune apache or change and reload the htaccess file it works....for a short while and then I get 404 errors...arggghhh...
I'd be very grateful for ANY help.
my htaccess is :
Options +FollowSymLinks
RewriteBase /store/
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule .* - [L]
RewriteRule ^sitemap.xml sitemap.php [QSA,L]
RewriteRule ^install.php install.php [QSA,L]
RewriteRule ^pict/([^/]+)?$ [thumbs.ebaystatic.com...] [QSA,L]
RewriteRule ^item123/([^/]+)?$ item123.php?i=$1 [QSA,L]
RewriteRule ^item123/view/(.*)?$ item123.php?i=view&u=$1 [QSA,L]
RewriteRule ^register.php item.php?i=register [QSA,L]
RewriteRule ^bans.php item.php?b=bans [QSA,L]
RewriteRule ^search/([^/]+)?$ index.php?mainCat=search&q=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)?$ index.php?mainCat=$1&subCat=$2 [QSA,L]
RewriteRule ^([^/]+)?$ index.php?mainCat=$1 [QSA,L]
~
Cheers
Dean
#1 - I have made another test without the rewriteMap with the code
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^:]+)
RewriteRule ^/([^/\.]+)/?$ /team.php?id=3 and this works ,every time I go to the url i see the
team.php?id=3 page Last test was changing the php prg called by the RewriteMap, i have deleted all the lines and it rerurn a simple "3". But the music is always the same. It works only the first time I go to the url. The second time i m redirected to
team.php?id= without the "3"! but why ? What I'm missing ?!?!
The RewriteMap program is started with Apache, and continues running, listening on STDIN, and writing responses to STDOUT. So you must be very careful with I/O buffering -- that is, don't use it. And of course, all per-request variables must be re-initialized for each new request.
You might also consider trying the intermediate step: Use a flat text file as a RewriteMap and see if that works; If so, you'll know it's a RewriteMap script problem. While that *is* the likely answer, it would still be good to know for sure before trying to debug the wrong thing.
Jim
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