Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have multiple Wordpress / Joomla instances under the same subfolder, is there a simple way to do the following statement in one location block?

location /site1/ {
  try_files $uri $uri/ site1/index.php;
location /site2/ {
  try_files $uri $uri/ site2/index.php; 

I'd like to do something like this:

location ^~ /site {
  try_files $uri $uri/ $variable/index.php;

Someone on IRC gave me this but it's not working :/

location ^~ /site {
  try_files $uri $uri/ @siteindex;
location @siteindex {
  rewrite ^(/site[^/]*) $1/index.php last;

Thank you!

share|improve this question
Does the rewrite like this work? rewrite ^/(site[^/]*) $1/index.php last; –  cjc Aug 8 '12 at 19:46
No, it's downloading a 'BIN' file, I have a location ~ \.php$ {} in the bottom of my conf file. –  Arg Aug 8 '12 at 20:01

1 Answer 1

There you go:

location ~* ^/([a-z0-9]+)$ {
  try_files $uri $uri/ /$1/index.php;
share|improve this answer

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.