Tim Gavin

Web Developer located in Coral Springs, FL

© 2010 Tim Gavin Contact Me

Use Twitter-style Usernames With Mod_rewrite

Today I was designing URIs for my current project — a social video site — and decided to make the user's home page reside at http://mysite.com/username, just like Twitter. Of course, I needed to use mod_rewrite for this.

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([A-Za-z0-9_]+)$ /account/index.php?uname=$1 [L]

All this does is it takes the username, which can only contain letters, numbers and underscores and send it to /account/index.php where we then lookup the user based on their unique user ID. Easy! Happy
Comments