I am fairly new to mod_rewrite, but what I'm trying to do is redirect HTTP requests from the format http://www.example.com/username to serve up content from a structured directory of users below my document root.

My document root is located at /var/www/html

To keep the usernames organized and secure, I have put them in /var/www/users/u/username where "/u" is the first alphanumeric character of "/username."

I cannot figure out the syntax of the rewrite rule. I think it should be something like this, but I know this isn't correct:

RewriteRule ^/(([a-z0-9])[a-z0-9]+)(.*) /var/www/users/$2/$1/$3

Can anybody help me figure out the correct syntax I'm looking for?

I don't know regex well enough to pull out the first letter of a word but it would be something like ^([a-z])([a-z0-9]+)$ /users/$1/$1$2 where $1 represents 'u' and $2 represents 'sername'. I'm probably totally wrong so feel free to make fun of me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.