# Help with rewrite rule

**URL:** <https://www.ruby-forum.com/t/help-with-rewrite-rule/215367>\
**Category:** NGINX\
**Created:** [January 2, 2012, 3:21am UTC](https://www.ruby-forum.com/t/help-with-rewrite-rule/215367 "2012-01-02T03:21:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 2, 2012, 3:21am UTC](https://www.ruby-forum.com/t/help-with-rewrite-rule/215367/1 "2012-01-02T03:21:17Z")

</div>

I’m trying to rewrite any png files referenced through the fancybox sub  
directory to a directory off of the images folder as follows:

rewrite ^/fancybox/(.+.png)$ /images/fancybox/$1 last;

This is not working, probably b/c my regex is off the mark. Any  
suggestions?

Thanks

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [January 2, 2012, 3:28am UTC](https://www.ruby-forum.com/t/help-with-rewrite-rule/215367/2 "2012-01-02T03:28:04Z")

</div>

Solved it with this rule:

```
rewrite ^(.*)/fancybox/(.+\.png)$ /images/fancybox/$2 last;

```

---------- Forwarded message ----------  
From: Ilan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Sun, Jan 1, 2012 at 9:20 PM  
Subject: Help with rewrite rule  
To: removed\_email\_address@domain.invalid

I’m trying to rewrite any png files referenced through the fancybox sub  
directory to a directory off of the images folder as follows:

rewrite ^/fancybox/(.+.png)$ /images/fancybox/$1 last;

This is not working, probably b/c my regex is off the mark. Any  
suggestions?

Thanks

–

Ilan B.  
Chief Technology Officer

> **[Time4Learning.com](https://www.time4learning.com)**
>
> Award-winning online curriculum teaching math, language arts, science, social studies and more! Great for homeschool, afterschool & summer use.

6300 NE 1st Ave., Suite 203  
Ft. Lauderdale, FL 33334  
(954) 771-0914

[http://www.twitter.com/time4learning](http://www.twitter.com/time4learning)  
[http://www.facebook.com/Time4Learning](http://www.facebook.com/Time4Learning)

[Time4Learning.com](http://Time4Learning.com) - Online interactive curriculum for home use, PreK-8th  
Grade.  
[Time4Writing.com](http://Time4Writing.com) - Online writing tutorials for high, middle, and  
elementary school students.  
[Time4Learning.net](http://Time4Learning.net) - A forum to chat with parents online about kids,  
education, parenting and more.  
[spellingcity.com](http://spellingcity.com) - Online vocabulary and spelling activities for  
teachers,  
parents and students.
