I need to remove .mp4 from www.foo.com/bar/rab/video.mp4

So I am left with www.foo.com/bar/rab/video

So far I have

location ~* ^/bar/rab/(.*)$ {
    rewrite ^/bar/rab/(.*)$/$(.mp4) /$1/$2 break;
    proxy_pass https://foo.s3.amazonaws.com;
}

However I think I am miles wrong, could anyone please explain and help me

:)

link|improve this question

50% accept rate
feedback

1 Answer

up vote 2 down vote accepted

How about:

location ~* ^/bar/(.*).mp4$ {
    rewrite ^/bar/(.*).mp4 /bar/$1 break;
    proxy_pass https://foo.s3.amazonaws.com;
}

Here's something about Perl-compatible Regular Expressions which is what nginx uses:

http://marvin.cs.uidaho.edu/~heckendo/CS445/regex.html

Here's a regex tester:

http://www.regextester.com/

So if you stick "^/bar/(.*).mp4" in the regex field (the first part of the rewrite), and put "/bar/rab/foo.mp4" in the text field, and then put "/bar/$1" in the replace-with field (the second part of the rewrite), you will get "/bar/rab/foo" as expected.

link|improve this answer
I have edited my question, could you have a look again please :) – OliverBS Jan 27 at 15:41
Well, you can just modify the pattern to have /rab in there. On the other hand, the pattern match is broad enough so that it will probably work as is. Why don't you try it? – cjc Jan 27 at 15:50
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.