matsumoto-r/ngx_mruby — pull request #57 by charlescui (2013-07-07 06:44:55+00:00)
Title: add Nginx.redirect to serve 2 kinds redirect

add Nginx.redirect to serve 2 kinds redirect:
1st,serve http 3xx redirection.
2nd,serve nginx internal redirection.

test 1:http 3xx redirection

```nginx
# redirect
# http://localhost/redirect?url=http://163.com
location /redirect {
mruby_rewrite_handler_code '
r = Nginx::Request.new()
if r.var.arg_url
Nginx.redirect r.var.arg_url
else
Nginx.redirect "http://taobao.com", 301
end
';
}
```

test 2:nginx internal redirection, such as rewrite syntax in nginx.

```nginx
# internal redirect
# http://localhost/redirect/internal?version=xxx
location /redirect/internal {
mruby_rewrite_handler_code '
Nginx.redirect "/vars"
';
}
```

test3:dynamic generate location and let nginx serve it, vary useful for dynamic location + static files.

```nginx
# dynamic the internal path for your business
# http://localhost/redirect/internal/dynamic/path?path=hello
# actually this request will served by location /static/
location /redirect/internal/dynamic/path {
mruby_rewrite_handler_code '
r = Nginx::Request.new()
dynamic_path = "/static/#{r.var.arg_path}"
Nginx.redirect dynamic_path
';
}

location /static/ {
alias /path/to/static/;
}
```