# Please help me with follow rewrite rule

**URL:** <https://www.ruby-forum.com/t/please-help-me-with-follow-rewrite-rule/196092>\
**Category:** NGINX\
**Created:** [October 6, 2010, 6:52pm UTC](https://www.ruby-forum.com/t/please-help-me-with-follow-rewrite-rule/196092 "2010-10-06T18:52:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![digginchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@digginchina](https://www.ruby-forum.com/u/digginchina)\
**Post date:** [October 6, 2010, 6:52pm UTC](https://www.ruby-forum.com/t/please-help-me-with-follow-rewrite-rule/196092/1 "2010-10-06T18:52:11Z")

</div>

here is the structure:  
/images/thumbnails/  
/watermark

i use follow rewrite rule to add a watermark on my pictures.

rewrite ^/images/(.\*).jpg /wm/wm.php?$request\_filename;

i found it will rewrite with images/_.jpg and image/thumbnails/_.jpg,  
but actually i only wanna rewrite images/\*.jpg, not subdirectories. then  
i change it to:

rewrite ^/images/(.[^/]).jpg /watermark/image.php?$request\_filename;

my opinion is fit all character except “/” so that i can remove all  
subdirectories from the rewrite rule.

but unfortunately, it doesn’t work well, /images/\*.jpg can’t be rewrited  
too.

is there anybody help me with this case?

thanks a lot.  
regards  
solo

Posted at Nginx Forum:

> **[please help me with follow rewrite rule.](https://forum.nginx.org/read.php?2,137829,137829#msg-137829)**
>
> here is the structure: /images/thumbnails/ /watermark i use follow rewrite rule to add a watermark on my pictures. rewrite ^/images/(.\*)\\.jpg /wm/wm.php?$request\_filename; i found it will rewrite with images/\*.jpg and image/thumbnails/\*.jpg,

---

<div class="post-metadata">

**Author:** ![digginchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@digginchina](https://www.ruby-forum.com/u/digginchina)\
**Post date:** [October 6, 2010, 7:16pm UTC](https://www.ruby-forum.com/t/please-help-me-with-follow-rewrite-rule/196092/2 "2010-10-06T19:16:12Z")

</div>

Hello!

On Wed, Oct 06, 2010 at 12:50:29PM -0400, digginchina wrote:

> i change it to:
> 
> rewrite ^/images/(.[^/]).jpg /watermark/image.php?$request\_filename;

- rewrite ^/images/(.[^/]).jpg /watermark/image.php?$request\_filename;

- rewrite ^/images/([^/]\*).jpg /watermark/image.php?$request\_filename;

> my opinion is fit all character except “/” so that i can remove all  
> subdirectories from the rewrite rule.
> 
> but unfortunately, it doesn’t work well, /images/\*.jpg can’t be rewrited  
> too.
> 
> is there anybody help me with this case?

Recommended reading:  
Jeffrey E.F. Friedl, “Mastering Regular Expressions”

And try pcre manpages, in particular ‘man pcrepattern’. Using  
pcretest to test things is good idea, too.

Maxim D.

---

<div class="post-metadata">

**Author:** ![digginchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@digginchina](https://www.ruby-forum.com/u/digginchina)\
**Post date:** [October 6, 2010, 7:47pm UTC](https://www.ruby-forum.com/t/please-help-me-with-follow-rewrite-rule/196092/3 "2010-10-06T19:47:13Z")

</div>

On 6 Out 2010 17h50 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> images/\*.jpg, not subdirectories. then i change it to:
> 
> rewrite ^/images/(.[^/]).jpg  
> /watermark/image.php?$request\_filename;

You regex is incorrect. Furthermore since you’re not doing any  
capturing or using alternative patterns drop the group.

rewrite ^/images/[^/]\*.jpg /watermark/image.php?$request\_filename;

It matches any file _only_ under the images directory ending in .jpg.

— appa

---

<div class="post-metadata">

**Author:** ![digginchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@digginchina](https://www.ruby-forum.com/u/digginchina)\
**Post date:** [October 7, 2010, 12:18am UTC](https://www.ruby-forum.com/t/please-help-me-with-follow-rewrite-rule/196092/4 "2010-10-07T00:18:16Z")

</div>

thanks a lot, prefect solution.

Posted at Nginx Forum:

> **[Re: please help me with follow rewrite rule.](https://forum.nginx.org/read.php?2,137829,137933#msg-137933)**
>
> here is the structure: /images/thumbnails/ /watermark i use follow rewrite rule to add a watermark on my pictures. rewrite ^/images/(.\*)\\.jpg /wm/wm.php?$request\_filename; i found it will rewrite with images/\*.jpg and image/thumbnails/\*.jpg,

---

<div class="post-metadata">

**Author:** ![digginchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@digginchina](https://www.ruby-forum.com/u/digginchina)\
**Post date:** [October 25, 2010, 12:53pm UTC](https://www.ruby-forum.com/t/please-help-me-with-follow-rewrite-rule/196092/5 "2010-10-25T12:53:49Z")

</div>

i found the forum remove my space… it should be

image/2010/thumb  
image/2009/thumb

thanks a lot.

Posted at Nginx Forum:

> **[Re: please help me with follow rewrite rule.](https://forum.nginx.org/read.php?2,137829,144285#msg-144285)**
>
> here is the structure: /images/thumbnails/ /watermark i use follow rewrite rule to add a watermark on my pictures. rewrite ^/images/(.\*)\\.jpg /wm/wm.php?$request\_filename; i found it will rewrite with images/\*.jpg and image/thumbnails/\*.jpg,

---

<div class="post-metadata">

**Author:** ![digginchina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@digginchina](https://www.ruby-forum.com/u/digginchina)\
**Post date:** [October 25, 2010, 9:12am UTC](https://www.ruby-forum.com/t/please-help-me-with-follow-rewrite-rule/196092/6 "2010-10-25T09:12:45Z")

</div>

hello Almeida,  
if there is a structure like:  
/images  
/2010  
/thumb  
/2009  
/thumb  
…  
if i want to match all jpg files in directory images, except jpg files  
in every thumb directories, what should use?  
i try

rewrite ^/images/[^/thumb/]\*.jpg  
/watermark/image.php?$request\_filename;

but it can’t work well…  
thanks a lot.  
regards  
solo

Posted at Nginx Forum:

> **[Re: please help me with follow rewrite rule.](https://forum.nginx.org/read.php?2,137829,144231#msg-144231)**
>
> here is the structure: /images/thumbnails/ /watermark i use follow rewrite rule to add a watermark on my pictures. rewrite ^/images/(.\*)\\.jpg /wm/wm.php?$request\_filename; i found it will rewrite with images/\*.jpg and image/thumbnails/\*.jpg,
