nginx block URI request but allow internal directory

Posted by Mike Anders on Server Fault See other posts from Server Fault or by Mike Anders
Published on 2013-10-30T21:03:00Z Indexed on 2013/10/30 21:58 UTC
Read the original article Hit count: 149

Filed under:

I'm new to nginx from apache. I'm trying to simply block the URIs: /_mydir/* => / (redirect)

But, I want to rewrite: /ex/(.*)$ => /_mydir/$1

I have tried: location /ex/ { rewrite ^/ex/(.*)$ /_mydir/$1 last; }

location /_mydir {
    rewrite ^/_mydir/(.*)$ http://$http_host/ redirect;
}

But what always happens is once I block the '/_mydir' directory the rewrite is also blocked.

I have also tried: location /_mydir/ { internal; } This also ends up blocking the rewrite.

All help is greatly appreciated, thanks.

UPDATE: I fixed this problem using: rewrite ^/ex/(.*)$ /_mydir/$1 break;

© Server Fault or respective owner

Related posts about nginx