0
votes

I need some help to understand the Nginx rewrite function.

Imagine, a real file is at the following address:

http://www.domain.com/library/content/folder/country/page/index.html

I want to rewrite the URL, to have something better (more human readable!):

http://www.domain.com/page

1. How can I do that with Nginx?

location = /... {
    rewrite ...
}

Or

if ($request ~* "page") {
    rewrite ...
}

2. How can I write this rule ?

If I was using Apache, I will write something like this:

RewriteRule ^page /(.*) library/contents/folder/contry/page/$1 [L]
2

2 Answers

1
votes

You can use the alias or root instructions in a location block

location /page/ {
    root /my/absolute/path/library/content/folder/country/;
}

location /page/ {
    alias /my/absolute/path/library/content/folder/country/page/;
}

Source: http://wiki.nginx.org/HttpCoreModule

0
votes

How about

This problem is related to versioning of API based on header

INPUT url : http://abcd.com/v1/getshafts?param=q ,header = v1.1

OUTPUT : abcd.com/v1.1/getshafts/

what should be 'rewrite' value here?