rgwozdz
rgwozdz

Reputation: 1143

Nginx rewrite rule: Add subfolder to URI if not there

Hello I'm trying to write a Nginx rewrite rule that adds a subdirectory to my URL if it's missing. For example, I need http://example.com to be re-written (and redirected) to http://example.com/legacy-app. Can't seem to find the proper example to do this.

Upvotes: 0

Views: 624

Answers (2)

rgwozdz
rgwozdz

Reputation: 1143

We ended up using this:

rewrite ^/$ /legacy-app/ last;

Upvotes: 0

Richard Smith
Richard Smith

Reputation: 49812

You can use a rewrite directive, but an exact match location block is most efficient:

location = / {
    return 301 /legacy-app;
}

See this document for more.

Upvotes: 1

Related Questions