Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Using the example regarding how to use sub directory aliases, I've noticed it does not mention how to do it dynamically.

In the following example...

location ~ ^/download/(.*)$ {
  alias /home/website/files/$1;

...the request "/download/book.pdf" will return the file "/home/website/files/book.pdf". Note again that only part of the request URI after the location is appended to the path defined by alias.

If I'm creating a folder labeled the username that the user created once signing up, then this folder name would always be unique and different. How do I alter the regex in the example above so that the word download also becomes a wild card sub directory?

location ~ ^/randomusername/(.*)$ {
  alias /home/website/profiles/randomusername/$1;
share|improve this question

You need a little background about regex.

Please try the code below and see if it helps.

location ~ ^/([^/]+)/([^/?]+)$ {
  alias /home/website/profiles/$1/$2;
share|improve this answer
This seems to work. All I need to find out is how to turn random_user_directory_here_123 into regex. location /random_user_directory_here_123 { root www/profiles; index index.php; } – Vini Apr 14 '11 at 19:58
Can anyone help? – Vini Apr 15 '11 at 13:01
K. Just delete this question. It's worthless. God how I miss – Vini Apr 16 '11 at 15:16

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.