1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

NGINX Rewrite

Discussion in 'Server Configuration and Hosting' started by akia, Sep 20, 2012.

  1. akia

    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?
  2. Juze

    Juze New Member

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

    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:

        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.

Share This Page