Forum Moderators: phranque
all requests for:
example.com/username
go to:
example.com/userinfo.php?user=username
and all requests for:
example.com/username/comments/
go to:
example.com/comments.php?user=username
The first one I managed to get working with the following rules:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^([^/\.]+)/?$ userinfo.php?user=$1[L]
Don't forget to sort out www and non-www domain canonicalisation within that same redirect rule, to avoid a redirection chain occuring with any of the other redirects on the site.
By preceding these URL-paths with /users/ (or something similar), you can greatly reduce the chances for 'collisions' between usernames and existing filenames, and also eliminate the need to check you filesystem to see if the requested URL exists as a file or directory for every single request made to your server. Doing so now will prevent the need for a re-design (or a server upgrade) in the future if your site gets busy.
Jim