Please help me with follow rewrite rule

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:
http://forum.nginx.org/read.php?2,137829,137829#msg-137829

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.

On 6 Out 2010 17h50 WEST, [email protected] 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

thanks a lot, prefect solution.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,137829,137933#msg-137933

i found the forum remove my space… it should be

image/2010/thumb
image/2009/thumb

thanks a lot.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,137829,144285#msg-144285

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:
http://forum.nginx.org/read.php?2,137829,144231#msg-144231

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs