# How to use location before rewrite

**URL:** <https://www.ruby-forum.com/t/how-to-use-location-before-rewrite/237304>\
**Category:** NGINX\
**Created:** [November 5, 2013, 2:52am UTC](https://www.ruby-forum.com/t/how-to-use-location-before-rewrite/237304 "2013-11-05T02:52:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [November 5, 2013, 2:52am UTC](https://www.ruby-forum.com/t/how-to-use-location-before-rewrite/237304/1 "2013-11-05T02:52:43Z")

</div>

I have a set of rewrite rules as

rewrite ^/(.\*) /script.php?file=$1 last;

location ~ .php$ {  
php proxy  
}

but I want to make a few exceptions as

location = file1|file2|file3 {  
static delivery  
}

but rewrite will change any static file to php file before the latter  
location.

I cannot use rewrite inside the location, as it should generate php  
script  
before location (and I have other locations for subdirectories too).

Posted at Nginx Forum:

> **[How to use location before rewrite](https://forum.nginx.org/read.php?2,244442,244442#msg-244442)**
>
> I have a set of rewrite rules as rewrite ^/(.\*) /script.php?file=$1 last; location ~ \\.php$ { php proxy } but I want to make a few exceptions as location = file1|file2|file3 { static delivery } but

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [November 5, 2013, 8:35am UTC](https://www.ruby-forum.com/t/how-to-use-location-before-rewrite/237304/2 "2013-11-05T08:35:35Z")

</div>

On Mon, Nov 04, 2013 at 08:51:53PM -0500, etrader wrote:

Hi there,

the answer to the question in the Subject: line is “you don’t”.

> location = file1|file2|file3 {  
> static delivery  
> }

Depending on the full plan, perhaps either put your rewrites inside  
“location / {}”; or add earlier rewrites of the form

rewrite ^(/file1)$ $1 last;

## f

Francis D. removed\_email\_address@domain.invalid
