Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15310

nginx url rewrite

How to nginx rewrite within location context the following:

/ => /myurl/

/abc/ => /myurl/abc/

Upvotes: 0

Views: 3800

Answers (2)

cobaco
cobaco

Reputation: 10546

the following will do the trick:

location / {
    rewrite ^ /myurl/$uri; 
}

Note that the /abc/ wil match the / prefix (and be rewritten to /myurl/abc/), so it doesn't need a sepperate rewrite

Also note that you need to add an additional "location /myurl/ {...}" block to avoid getting incoming request to that url to get rewritten to /myurl/myurl/... and so on

Upvotes: 5

Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15310

Looks like this does the trick:

rewrite ^(/.*)$  ^/admin/$1 break;

Any other suggestion?

Upvotes: 0

Related Questions