Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Lets say i get a GET request to file /dir/01/23/file.ext. I would like to serve the file /dir/01/23 which is an extensionless file. The filename should be file.ext rather then 03 and the mime of .ext should be used. How do i write a rule in nginx to do that?

share|improve this question
rewrite  ^/dir/01/23/file.ext$  /dir/01/23  break;


rewrite  ^(.*)/file.ext$  $1  break;

you may also need to specify dedicated location. For example:

location /dir {
  root   $docroot;
share|improve this answer
I believe that will work but i wont be able to try until tomorrow. Nice answer – acidzombie24 Nov 21 '11 at 15:03

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.