Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

:)

share|improve this question

1 Answer 1

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.

share|improve this answer
    
I have edited my question, could you have a look again please :) –  OliverBS 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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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