# Location regexp with multiple Wordpress install

**URL:** <https://www.ruby-forum.com/t/location-regexp-with-multiple-wordpress-install/207723>\
**Category:** NGINX\
**Created:** [June 1, 2011, 12:00pm UTC](https://www.ruby-forum.com/t/location-regexp-with-multiple-wordpress-install/207723 "2011-06-01T12:00:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 1, 2011, 12:00pm UTC](https://www.ruby-forum.com/t/location-regexp-with-multiple-wordpress-install/207723/1 "2011-06-01T12:00:14Z")

</div>

Hello,

I have a problem with my location rules.  
I would like to generate a generic location rule for each folder that  
contains a WordPress installation.

location / {  
try\_files $uri $uri/ /index.html;  
}

location /user1/ {  
try\_files $uri $uri/ /user1/index.php?q=$uri&$args;  
}

location ~\* ^/(user2|user3)/ {  
try\_files $uri $uri/ /$1/index.php?q=$uri&$args;  
}

location ~ .php$ {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
include fastcgi\_params;  
}

If I go to localhost/user1/, I am redirected to the good Wordpress. But,  
if I go to localhost/user2/ my browser downloads a file containing the  
source code of index.php.  
How to get it working?

Thank you.

Posted at Nginx Forum:

> **[Location regexp with multiple Wordpress install](https://forum.nginx.org/read.php?2,202924,202924#msg-202924)**
>
> Hello, I have a problem with my location rules. I would like to generate a generic location rule for each folder that contains a WordPress installation. location / { try\_files $uri $uri/ /index.html; } location /user1/ {

---

<div class="post-metadata">

**Author:** ![Amanager](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@Amanager](https://www.ruby-forum.com/u/Amanager)\
**Post date:** [June 1, 2011, 12:10pm UTC](https://www.ruby-forum.com/t/location-regexp-with-multiple-wordpress-install/207723/2 "2011-06-01T12:10:06Z")

</div>

On Wed, Jun 01, 2011 at 05:59:30AM -0400, Amanager wrote:

> location /user1/ {  
> include fastcgi\_params;  
> }
> 
> If I go to localhost/user1/, I am redirected to the good Wordpress. But,  
> if I go to localhost/user2/ my browser downloads a file containing the  
> source code of index.php.  
> How to get it working?

This is why I do not like regex locations - you have always to watch  
over order of these locations. In this case you should place  
“location ~ .php$” before “location ~\* ^/(user2|user3)/”.  
You will use only usual locations, you can place it in any order.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Amanager](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@Amanager](https://www.ruby-forum.com/u/Amanager)\
**Post date:** [June 1, 2011, 1:36pm UTC](https://www.ruby-forum.com/t/location-regexp-with-multiple-wordpress-install/207723/3 "2011-06-01T13:36:03Z")

</div>

Thank you very much Igor.  
It works.

Posted at Nginx Forum:

> **[Re: Location regexp with multiple Wordpress install](https://forum.nginx.org/read.php?2,202924,202951#msg-202951)**
>
> Hello, I have a problem with my location rules. I would like to generate a generic location rule for each folder that contains a WordPress installation. location / { try\_files $uri $uri/ /index.html; } location /user1/ {
