Skip to content

Instantly share code, notes, and snippets.

@frozenminds
Created July 14, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozenminds/d39ed1ce80a7245d2a36 to your computer and use it in GitHub Desktop.
Save frozenminds/d39ed1ce80a7245d2a36 to your computer and use it in GitHub Desktop.
Nginx rewrite parameter "p" to "page" using Lua
server {
...
rewrite_by_lua '
-- get query args
local args = ngx.req.get_uri_args()
if args.p ~= nil then
args.page = args.p
args.p = nil
-- perform redirect
-- @see http://wiki.nginx.org/HttpLuaModule#ngx.redirect
-- @see http://wiki.nginx.org/HttpLuaModule#HTTP_status_constants
ngx.redirect((ngx.var.uri or "/") .. (ngx.var.is_args or "") .. ngx.encode_args(args), ngx.HTTP_MOVED_PERMANENTLY)
end
';
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment