Using mod rewrite to change URL with username variable

Solution 1:

Try this rule:

RewriteRule ^profile/([^/]+)$ profile.php?user_name=$1

This will rewrite requests of /profile/foobar to /profile.php?user_name=foobar. Note that you just can rewrite the user name. You script will then have to look up the user ID if necessary.

Solution 2:

Checkout the RewriteMap function.