views:

33

answers:

2

I have a link, let's say: http://site.com/profile.php?id=1 ....In a normal mode, with a normal rewrite I'd have something like: http://site.com/profile/1 . But,...What I want is.....how can I get from the database the username that belongs to the user with the id 1 and make the url http://site.com/profile/FinalDestiny ?

Thanks,

A: 

You want to make a rule which rewrites http://site.com/profile/FinalDestiny to http://site.com/profile.php?username=FinalDestiny and then do a database query in profile.php to find the id of the user with that username.

Lethargy
Nono, I want to use ID ...http://site.com/profile.php?id=1. with profile.php?username=FinalDestiny I know how to do it too..but I want with id.
FinalDestiny
+2  A: 

You could use the RewriteMap function of mod_rewrite, but you have to store your id-username pairs either into a text file or a DBM file-based database. Keep in mind that to use this directive you have first to declare it inside httpd.conf, so access and write permissions to httpd.conf are required.

If your users are stored in another database (MySQL or such) I'd suggest you use a text file and simply overwrite it any time an user is added or deleted.

If you've got enough users to make using a DBM a sensible choice you can either try to use PHP's DBA functions or make a text file as above and use Apache's utility httxt2dbm to convert it into a database (via exec() or such).

RewriteMap also allows using an external program (say, a PHP CLI script) to return the URL mapping, but it seems like overkill...

djn