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,
You could use the
RewriteMapfunction ofmod_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).RewriteMapalso allows using an external program (say, a PHP CLI script) to return the URL mapping, but it seems like overkill…