Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to accomplish the following with mod_rewrite:

URI request: or
URI translate:

This needs to be very specific, with no wildcards. Could an expert on mod_rewrite and regex lend a hand? Thanks!

share|improve this question
How do you want to do this with no wildcards if "username" will be changing? Or is this for a specific username? – Dave Drager Sep 18 '09 at 13:15
What I meant was, the ruleset needs to be as specific (strict) as possible as to not interfere with another. It needs to match /user/variableusername precisely. The "variableusername" will always be lowercase alphabetic. – user1797 Sep 18 '09 at 13:23
I thought of something like: "RewriteRule ^user/[a-z]$ /?q=user/$1", but it doesn't work. – user1797 Sep 18 '09 at 13:25
Add answer seems to be broken, here is what I came up with: The best I could come up with is to create a /user/ directory and add this into it's .htaccess file: RewriteEngine on RewriteRule ^(\w+) /?q=user/$1 [R,L] I think there is a way to do this by putting .htaccess in the root web directory but I couldn't seem to make it work without getting into a loop. The above script will trim out anything after a "username", for example if someone requested it would still redirect to – Dave Drager Sep 18 '09 at 13:47
up vote 1 down vote accepted

I think you're forgetting the + after the [a-z]:

RewriteRule ^user/([a-z]+)$ /?q=user/$1 [L]

I tried on my server and it works.

share|improve this answer
This does it. Thanks! – user1797 Sep 18 '09 at 14:45

I tried:

RewriteRule ^user/[a-z]$        /?q=user/$1

But it doesn't work. Dave Drager, I am looking for a cleaner version (not sure if your approach will work, but would rather not create a directory, want all from .htaccess).

share|improve this answer
I'm going crazy, It won't let me add an answer, says "page doesn't exist"! Try RewriteRule ^/user/(\w+) /?q=user/$1 [R,L] – Dave Drager Sep 18 '09 at 14:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.