stecog
stecog

Reputation: 2344

nginx:howto redirect 2 links to same path

I need redirect 2 link to same folder, ex.

www.domain.com ---> /path/to/files

www.domain.com/foo ---> /path/to/files

I have tried with "location" but don't work:

server {

listen 81;
server_name domain.com;
index index.php index.html;
root /path/to/files;
location /foo {
root /path/to/files;
index index.html;
 }
}

Upvotes: 0

Views: 52

Answers (2)

Alexey Ten
Alexey Ten

Reputation: 14364

location /foo {
    alias /path/to/files;
}

or

location /foo/ {
    alias /path/to/files/;
}

Be careful with trailing slashes.

See http://nginx.org/r/alias for details.

Upvotes: 1

Stefano Falsetto
Stefano Falsetto

Reputation: 572

You must use a rewrite:

location /foo {
    root /path/to/files;
    index index.html;
    rewrite ^/foo(/.*|)$ $1 break;
}

Upvotes: 0

Related Questions