Forum: NGINX rewriting a filename in any directory

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6cde979c8ef08ccd0088e541b56f92b9?d=identicon&s=25 Aaron (Guest)
on 2009-01-23 07:42
(Received via mailing list)
I am trying to achieve the following:

Request: http://www.domain.com/images/afv-585785-something.gif
Would normally retrieve from : /public/images/afv-585785-something.gif

I need it to actually retrieve : /public/images/something.gif

So basically it needs to remove the "afv-######-" portion from the file
request.

I am doing this for cache/expire versioning purposes. I tried the
following but it only works on the root folder and not subdirectories.

location / {
rewrite ^(.*)/afv-(.*)-(.*)$ $1/$3 last;
}

What am I doing wrong?

Thanks,
Bompus
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-23 10:05
(Received via mailing list)
On Thu, Jan 22, 2009 at 11:31:01PM -0700, Aaron wrote:

> following but it only works on the root folder and not subdirectories.
>
> location / {
> rewrite ^(.*)/afv-(.*)-(.*)$ $1/$3 last;
> }
>
> What am I doing wrong?

What do you mean by subdirectories ?
6cde979c8ef08ccd0088e541b56f92b9?d=identicon&s=25 Aaron (Guest)
on 2009-01-23 17:19
(Received via mailing list)
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-23 18:06
(Received via mailing list)
On Fri, Jan 23, 2009 at 09:09:22AM -0700, Aaron wrote:

> My current rewrite works for http://www.domain.com/af-856757-filename.txt
> but not for http://www.domain.com/directory/af-656556-filename.txt

Do you have

     location /directory/ {

?
6cde979c8ef08ccd0088e541b56f92b9?d=identicon&s=25 Aaron (Guest)
on 2009-01-23 19:58
(Received via mailing list)
No.. We have MANY directories and I need a rewrite rule that will work
for all subdirectories as well as the root without having to specify
the location for each directory.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-23 20:09
(Received via mailing list)
On Fri, Jan 23, 2009 at 11:47:50AM -0700, Aaron wrote:

> No.. We have MANY directories and I need a rewrite rule that will work
> for all subdirectories as well as the root without having to specify
> the location for each directory.

If only "location /" matches /directory/, then it should work.

Also you may set

       rewrite ^(.*)/afv-(.*)-(.*)$ $1/$3 last;

on server level, then it will work for all locations.
This topic is locked and can not be replied to.