# Merge two location site to 1 location

**URL:** <https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449>\
**Category:** NGINX\
**Created:** [January 7, 2011, 3:02pm UTC](https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449 "2011-01-07T15:02:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 7, 2011, 3:02pm UTC](https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449/1 "2011-01-07T15:02:12Z")

</div>

Now i’ll write two sections of location as follow:  
location =/aaa{}  
location =/BBB{}  
But I want to write the two sections to one location? eg. location  
=/[aaa,BBB]{} , but it’s wrong, and does someone know how to write it?  
Thanks in advance.

Posted at Nginx Forum:

> **[merge two location site to 1 location](https://forum.nginx.org/read.php?2,164316,164316#msg-164316)**
>
> Now i'll write two sections of location as follow: location =/aaa{} location =/BBB{} But I want to write the two sections to one location? eg. location =/\[aaa,BBB\]{} , but it's wrong, and does someone know how to write it? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![kevinew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kevinew](https://www.ruby-forum.com/u/kevinew)\
**Post date:** [January 7, 2011, 3:16pm UTC](https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449/2 "2011-01-07T15:16:39Z")

</div>

On 7 Jan 2011 14h00 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Now i’ll write two sections of location as follow: location =/aaa{}  
> location =/BBB{} But I want to write the two sections to one  
> location? eg. location =/[aaa,BBB]{} , but it’s wrong, and does  
> someone know how to write it? Thanks in advance.

Yes but _without_ exact matching like you have. AFAIK you need a  
regex.

location ~\* ^/(?:aaa|BBB)$ {  
…  
}  
— appa

---

<div class="post-metadata">

**Author:** ![kevinew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kevinew](https://www.ruby-forum.com/u/kevinew)\
**Post date:** [January 7, 2011, 3:20pm UTC](https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449/3 "2011-01-07T15:20:25Z")

</div>

On Fri, Jan 7, 2011 at 9:00 PM, kevinew [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Now i’ll write two sections of location as follow:  
> location =/aaa{}  
> location =/BBB{}  
> But I want to write the two sections to one location? eg. location  
> =/[aaa,BBB]{} , but it’s wrong, and does someone know how to write it?  
> Thanks in advance.

if you want it to contain same thing, just create another file and  
include that file:

location = /aaa {  
include blah;  
}  
location = /bbb {  
include blah;  
}

alternatively someone may have made a tool to batch such job.

Or the slow (and therefore not recommended) way:

location ~ ^/(aaa|bbb)$ {  
…  
}

I had the idea to create a glob-like syntax which expands the  
expression automatically upon loading config but as I don’t have  
enough C skill and apparently there’s already tool for that (and  
deemed sufficient), it’s never got implemented.

---

<div class="post-metadata">

**Author:** ![kevinew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kevinew](https://www.ruby-forum.com/u/kevinew)\
**Post date:** [January 7, 2011, 3:37pm UTC](https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449/4 "2011-01-07T15:37:57Z")

</div>

On 7 Jan 2011 14h10 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Oops must be case sensitive since you stated AAA and bbb:

> location ~\* ^/(?:aaa|BBB)$ {  
> ^^  
> Becomes:  
> location ~ ^/(?:aaa|BBB)$ {  
> …  
> }  
> — appa

---

<div class="post-metadata">

**Author:** ![kevinew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kevinew](https://www.ruby-forum.com/u/kevinew)\
**Post date:** [January 7, 2011, 6:08pm UTC](https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449/5 "2011-01-07T18:08:18Z")

</div>

Hi APPA, Thank you greatly! you are so helpful~ I’ll use your case  
sensitive one.

Posted at Nginx Forum:

> **[Re: merge two location site to 1 location](https://forum.nginx.org/read.php?2,164316,164361#msg-164361)**
>
> Now i'll write two sections of location as follow: location =/aaa{} location =/BBB{} But I want to write the two sections to one location? eg. location =/\[aaa,BBB\]{} , but it's wrong, and does someone know how to write it? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![kevinew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kevinew](https://www.ruby-forum.com/u/kevinew)\
**Post date:** [January 7, 2011, 6:36pm UTC](https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449/6 "2011-01-07T18:36:34Z")

</div>

Hello!

On Fri, Jan 07, 2011 at 09:19:08PM +0700, Edho P Arief wrote:

> include that file:  
> Or the slow (and therefore not recommended) way:
> 
> location ~ ^/(aaa|bbb)$ {  
> …  
> }

Note that regexp location is _NOT_ the same thing. Location given  
by regular expressions are quite different from “selecting  
matching location” perspective.

E.g. for request “/aaa” this configuration will select “location =  
/aaa”:

```
location ~ a { ... }
location = /aaa { ... }
location = /bbb { ... }

```

But this one will select “location ~ a” instead:

```
location ~ a { ... }
location ~ ^/(aaa|bbb)$ { ... }

```

Maxim D.

---

<div class="post-metadata">

**Author:** ![kevinew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kevinew](https://www.ruby-forum.com/u/kevinew)\
**Post date:** [January 7, 2011, 6:13pm UTC](https://www.ruby-forum.com/t/merge-two-location-site-to-1-location/201449/7 "2011-01-07T18:13:20Z")

</div>

It’s better to make a tool to batch such job. As you said there is  
already tool for that, and are you convenient to share a copy for us?

Posted at Nginx Forum:

> **[Re: merge two location site to 1 location](https://forum.nginx.org/read.php?2,164316,164363#msg-164363)**
>
> Now i'll write two sections of location as follow: location =/aaa{} location =/BBB{} But I want to write the two sections to one location? eg. location =/\[aaa,BBB\]{} , but it's wrong, and does someone know how to write it? Thanks in advance.
