user3325376
user3325376

Reputation: 198

remove first folder in nginx

I have some URLs like:

http://example.com/username/file.zip
http://example.com/username/videos/aaa.avi
http://example.com/username/videos/abc/asdfdef/aaa.avi

the real path of files are:

/file.zip
/videos/aaa.avi
/videos/abc/asdfdef/aaa.avi

so basically I need to remove first folder in the URL I tried to use this rewrite rule :

rewrite ^/.*/(.*)$ /$1 last;

but its remove all folders and grep just the filename, it's work just for first URL and i get 404 error for rest of them

- P.S: the username could be anything

Upvotes: 0

Views: 480

Answers (1)

siavash khansari
siavash khansari

Reputation: 51

i didnt test it but based on that nginx uses pcre library i think

rewrite ^/.*?/(.*)$ /$1 last;

would work.

.*? matches any character between zero and unlimited times, as few times as possible, expanding as needed (lazy)

Upvotes: 1

Related Questions