# Help with Location Directives needed

**URL:** <https://www.ruby-forum.com/t/help-with-location-directives-needed/194778>\
**Category:** NGINX\
**Created:** [September 10, 2010, 11:53am UTC](https://www.ruby-forum.com/t/help-with-location-directives-needed/194778 "2010-09-10T11:53:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmsmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@tmsmaster](https://www.ruby-forum.com/u/tmsmaster)\
**Post date:** [September 10, 2010, 11:53am UTC](https://www.ruby-forum.com/t/help-with-location-directives-needed/194778/1 "2010-09-10T11:53:16Z")

</div>

Hi,  
i am having some troubles with location directives. As only the first  
matching location directive is executed (if there is no rewrite of  
course) i have to do a little hack to get my config to work. This  
currently looks like this:

location ~ “^/(js|css|audio)/(.\*)” {  
add\_header “Header1” “Value1”;  
if ($args !~ ^$) {  
add\_header “Header1” “Value1”;  
expires max;  
}  
}

location ~ “^/img/(.\*)” {  
if ($args !~ ^$) {  
expires max;  
}  
}  
this works for now 🙂  
what i actually only want to achieve:

- set expires max for all files in img js css audio if some query params  
are set (in this case just some value for cache busting purposes)
- set the Header1 if the file lies in js css audio

In this current config this is quite tricky as i have to set both  
headers in seperatetly for every case.  
Is there any way this config can be optimized? It would be really nice  
if something like this would work:  
location ~ “^/(js|css|audio|img)/(.\*)” {  
if ($args !~ ^$) {  
expires max;  
}  
}

location ~ “^/(js|css|audio)/(.\*)” {  
add\_header “Header1” “Value1”;  
}

Any ideas?

Sebastian

Posted at Nginx Forum:

> **[Help with Location Directives needed](https://forum.nginx.org/read.php?2,129102,129102#msg-129102)**
>
> Hi, i am having some troubles with location directives. As only the first matching location directive is executed (if there is no rewrite of course) i have to do a little hack to get my config to work. This currently looks like this: location ~...
