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...