NGINX Rewrite

akia

Well-known member
Can someone help me with a nginx location rewrite.

I've currently got a folder called directory with lots of files and sub folders in there.

I want to redirect everything in this folder to the root of the folder, So that if they vist www.site.com/directory/sheffield/varsity/ they end up at ww.site.com/directory/

Is this even possible?
 
Not completely sure what you meant, but have a look:

Code:
server {
    listen      80;
    server_name www.site.com;
    root  /path/to/root;
 
    location /directory/sheffield/varsity/ {
        return 301 $scheme://www.site.com/directory/;
    }
}

See how that works for you. It uses 301 Moved Permamently, hardcoded for now. You can also use this:

Code:
    location /directory {
        autoindex off;
    }

That way, if someone accesses /directory, they can't see the file list there unless they know a direct link. You can also use "internal" or "allow 127.0.0.1 deny all" if you need to completely remove permissions.
 
Top Bottom