Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to remove .mp4 from

So I am left with

So far I have

location ~* ^/bar/rab/(.*)$ {
    rewrite ^/bar/rab/(.*)$/$(.mp4) /$1/$2 break;

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


share|improve this question
up vote 2 down vote accepted

How about:

location ~* ^/bar/(.*).mp4$ {
    rewrite ^/bar/(.*).mp4 /bar/$1 break;

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.

share|improve this answer
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 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.