NGINX Rewrite


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 they end up at

Is this even possible?


New member
Not completely sure what you meant, but have a look:

server {
    listen      80;
    root  /path/to/root;
    location /directory/sheffield/varsity/ {
        return 301 $scheme://;
See how that works for you. It uses 301 Moved Permamently, hardcoded for now. You can also use this:

    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 deny all" if you need to completely remove permissions.