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



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:


Here's a regex tester:


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.

  • I have edited my question, could you have a look again please :) – Oliver Bayes-Shelton Jan 27 '12 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 '12 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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