# Using 'set' values in 'location'?

**URL:** <https://www.ruby-forum.com/t/using-set-values-in-location/202435>\
**Category:** NGINX\
**Created:** [January 28, 2011, 11:12pm UTC](https://www.ruby-forum.com/t/using-set-values-in-location/202435 "2011-01-28T23:12:42Z")\
**Posts on this page:** 1\
**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 28, 2011, 11:12pm UTC](https://www.ruby-forum.com/t/using-set-values-in-location/202435/1 "2011-01-28T23:12:42Z")

</div>

I’m still working on getting nginx installed but I want to get a head  
start on the configuration. I have a couple questions regarding ‘set’:

1. Can I use variables I create with ‘set’ in ‘location’ as regular  
strings? Such as:

```auto
server {
  set $subdir "/somesubdir";

  location $subdir/ {
    try_files $uri $uri/ $subdir/index.php;
  }
}
```

1. Can I use variables I create with ‘set’ in ‘location’ regular  
expressions? Such as:

```auto
server {
  set $subdir "/somesubdir";

  location ~ ^$subdir(.*/)?anotherdir/$ {
    rewrite ^ $subdir/index.php last;
  }
}
```

I recognize that probably isn’t correct syntax for the regular  
expression portion since $ indicates ‘match end of string’, but my goal  
here should be clear.

Also open to alternative solutions. I am aware that “if is evil” and  
I’ve read the “pitfalls” wiki documentation, so I was trying to avoid  
using ‘if’ and try to use ‘location’ and ‘rewrite’/‘try\_files’  
exclusively. I also don’t have access to a working nginx server yet or  
I’d probably just test it myself.

–  
Jack

Posted at Nginx Forum:

> **[Using 'set' values in 'location'?](https://forum.nginx.org/read.php?2,170551,170551#msg-170551)**
>
> I'm still working on getting nginx installed but I want to get a head start on the configuration. I have a couple questions regarding 'set': 1) Can I use variables I create with 'set' in 'location' as regular strings? Such as: \[code\] server { set...
