Created
July 14, 2015 16:25
-
-
Save frozenminds/d39ed1ce80a7245d2a36 to your computer and use it in GitHub Desktop.
Nginx rewrite parameter "p" to "page" using Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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