Reputation: 198
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
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