# Expires headers for url rewrite rules

**URL:** <https://www.ruby-forum.com/t/expires-headers-for-url-rewrite-rules/237039>\
**Category:** NGINX\
**Created:** [October 21, 2013, 11:53am UTC](https://www.ruby-forum.com/t/expires-headers-for-url-rewrite-rules/237039 "2013-10-21T11:53:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [October 21, 2013, 11:53am UTC](https://www.ruby-forum.com/t/expires-headers-for-url-rewrite-rules/237039/1 "2013-10-21T11:53:33Z")

</div>

In my config I have some url rewrite rules for images as seen below:

location / {  
rewrite ^/custom/path/(._)/(._)-(.\*).jpg$  
/media/images/products/$1/$3.jpg last;  
}

They work just fine. I’m also trying to set Expire headers for all  
static  
resources (images, css, js). I’ve added the following block for that:

location ~\* .(js|css|png|jpg|jpeg|gif|ico)$ {  
expires 1y;  
}

This works fine for everything except for the images that have the url  
rewrite rules (which return 404 Not found). Anyone know what I’m doing  
wrong  
here?

Thanks

Posted at Nginx Forum:

> **[Expires headers for url rewrite rules](https://forum.nginx.org/read.php?2,243888,243888#msg-243888)**
>
> In my config I have some url rewrite rules for images as seen below: location / { rewrite ^/custom/path/(.\*)/(.\*)-(.\*).jpg$ /media/images/products/$1/$3.jpg last; } They work just fine. I'm also trying to set Expire headers for all static resources...

---

<div class="post-metadata">

**Author:** ![bogdanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a88e4f/32.png) [@bogdanb](https://www.ruby-forum.com/u/bogdanb)\
**Post date:** [October 21, 2013, 11:58am UTC](https://www.ruby-forum.com/t/expires-headers-for-url-rewrite-rules/237039/2 "2013-10-21T11:58:49Z")

</div>

On Mon, Oct 21, 2013 at 05:52:57AM -0400, bogdanb wrote:

Hi there,

> location / {

> location ~\* .(js|css|png|jpg|jpeg|gif|ico)$ {

> This works fine for everything except for the images that have the url  
> rewrite rules (which return 404 Not found). Anyone know what I’m doing wrong  
> here?

One request is handled in one location.

Put all of the configuration that you want to apply to a request, within  
the one location{} block that handles that request.

## f

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

---

<div class="post-metadata">

**Author:** ![bogdanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a88e4f/32.png) [@bogdanb](https://www.ruby-forum.com/u/bogdanb)\
**Post date:** [October 21, 2013, 12:52pm UTC](https://www.ruby-forum.com/t/expires-headers-for-url-rewrite-rules/237039/3 "2013-10-21T12:52:35Z")

</div>

Moving the rewrite rules inside the " ~\*  
.(js|css|png|jpg|jpeg|gif|ico)$ {  
" block did the trick.

Thanks a lot for the quick reply.

## Francis D. Wrote:

> > rewrite rules (which return 404 Not found). Anyone know what I’m  
> > –  
> > Francis D. removed\_email\_address@domain.invalid
> 
> * * *
> 
> nginx mailing list  
> removed\_email\_address@domain.invalid  
> [nginx Info Page](http://mailman.nginx.org/mailman/listinfo/nginx)

Posted at Nginx Forum:

> **[Re: Expires headers for url rewrite rules](https://forum.nginx.org/read.php?2,243888,243895#msg-243895)**
>
> In my config I have some url rewrite rules for images as seen below: location / { rewrite ^/custom/path/(.\*)/(.\*)-(.\*).jpg$ /media/images/products/$1/$3.jpg last; } They work just fine. I'm also trying to set Expire headers for all static resources...
