You can't use a .htaccess RewriteRule only for this. If the forum exposes database internal IDs, you have mostly to rewrite parts of the SQL query. Basically you need to accept $_GET["username"]
instead of "userid"
first, and then rewrite the lookup. As example:
db_query("SELECT * FROM users WHERE id=?", (int)$_GET["userid"]);
to
db_query("SELECT * FROM users WHERE username=?", encode($_GET["username"]));
Depends on the application, the actual SQL table structure, and the DB interface (your forum probably uses mysql_query
and mysql_real_escape_string
instead of encode
).
After that you can deploy a simple RewriteCond !-f {%..}
and RewriteRule (.+) /viewprofile?username=$1
to get short URLs.