# Rewrite question

**URL:** <https://www.ruby-forum.com/t/rewrite-question/189592>\
**Category:** NGINX\
**Created:** [June 3, 2010, 5:50pm UTC](https://www.ruby-forum.com/t/rewrite-question/189592 "2010-06-03T17:50:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![axel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@axel](https://www.ruby-forum.com/u/axel)\
**Post date:** [June 3, 2010, 5:50pm UTC](https://www.ruby-forum.com/t/rewrite-question/189592/1 "2010-06-03T17:50:56Z")

</div>

Hi guys,

stupid but tricky question. In my “server” configuration, I added two  
“location” directives:

location ~\* .css|.js|.jpg|.jpeg|.png|.gif|.swf|.svg|.tiff$ {  
expires 30d;  
}

location /medias/ {  
rewrite ^/medias/(.\*) [http://static.mydomain.com/$1](http://static.mydomain.com/$1) permanent;  
}

The rewrite works fine except for jpg files. I suppose there is a  
conflict between the two locations. It works if I comment out the first  
location. I tried to invert locations or to add a “break;” after the  
rewrite command or to replace “permanent” with “last” or “break”.  
Nothing does the trick.

If you have any idea, that would be great.

Tks

Axel

---

<div class="post-metadata">

**Author:** ![axel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@axel](https://www.ruby-forum.com/u/axel)\
**Post date:** [June 3, 2010, 6:00pm UTC](https://www.ruby-forum.com/t/rewrite-question/189592/2 "2010-06-03T18:00:53Z")

</div>

Maybe try to put the /medias/ location on top?

---

<div class="post-metadata">

**Author:** ![axel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@axel](https://www.ruby-forum.com/u/axel)\
**Post date:** [June 3, 2010, 6:11pm UTC](https://www.ruby-forum.com/t/rewrite-question/189592/3 "2010-06-03T18:11:26Z")

</div>

Hello!

On Thu, Jun 03, 2010 at 05:50:08PM +0200, Axel wrote:

> stupid but tricky question. In my “server” configuration, I  
> added two “location” directives:
> 
> location ~\* .css|.js|.jpg|.jpeg|.png|.gif|.swf|.svg|.tiff$ {  
> expires 30d;  
> }
> 
> location /medias/ {

- location /medias/ {

- location ^~ /medias/ {

> rewrite ^/medias/(.\*) [http://static.mydomain.com/$1](http://static.mydomain.com/$1) permanent;  
> }
> 
> The rewrite works fine except for jpg files. I suppose there is  
> a conflict between the two locations. It works if I comment out  
> the first location. I tried to invert locations or to add a  
> “break;” after the rewrite command or to replace “permanent”  
> with “last” or “break”. Nothing does the trick.

See here for details:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Maxim D.

---

<div class="post-metadata">

**Author:** ![axel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@axel](https://www.ruby-forum.com/u/axel)\
**Post date:** [June 3, 2010, 6:17pm UTC](https://www.ruby-forum.com/t/rewrite-question/189592/4 "2010-06-03T18:17:52Z")

</div>

@kleinchris: on top didn’t work

@maxime: nice, did the trick. Tks a lot

Axel

Le 3 juin 2010 à 18:10, Maxim D. a écrit :
