Maca
Maca

Reputation: 1689

Nginx rewrite by directory

Trying to redirect a file in Nginx.conf but unsuccessful. I want to redirect from the directory

/data/file/static/sites/index.html

to

/data/file/static/sites/desktop/index.html

My nginx.conf

server {
    listen              80;
    server_name test.com;
    root    /data/file/static/sites;

  location /data/file/static/sites/index.html {
    rewrite ^(.*)$ /data/file/static/sites/desktop/index.html break;
  }

}

Upvotes: 0

Views: 120

Answers (2)

Lax
Lax

Reputation: 71

try this:

location /index.html {
  rewrite ^(.*)$ /desktop/index.html break;
}

since you have root /data/file/static/sites;, you don't need the full path in location.

Upvotes: 1

Tan Hong Tat
Tan Hong Tat

Reputation: 6864

Try

rewrite ^/index.html$ /desktop/index.html redirect;

Upvotes: 0

Related Questions