[ nginx ] 根據accept-language來重導網址
先安裝nginx-extras
>> sudo apt-get install nginx-extras
編輯nginx設定檔
location = /public/privacy/ {
rewrite_by_lua '
for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do
if string.sub(lang, 0, 2) == "en" then
ngx.redirect("/public/privacy/en/")
end
if string.sub(lang, 0, 2) == "zh" then
ngx.redirect("/public/privacy/zh")
end
end
ngx.redirect("/public/privacy/en/")
';
}
>> sudo apt-get install nginx-extras
編輯nginx設定檔
location = /public/privacy/ {
rewrite_by_lua '
for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do
if string.sub(lang, 0, 2) == "en" then
ngx.redirect("/public/privacy/en/")
end
if string.sub(lang, 0, 2) == "zh" then
ngx.redirect("/public/privacy/zh")
end
end
ngx.redirect("/public/privacy/en/")
';
}
重新啟動nginx即可
>> sudo service nginx restart
Rederence : http://www.cybrilla.com/blog/auto-redirect-based-on-language-in-nginx/
Rederence : http://www.cybrilla.com/blog/auto-redirect-based-on-language-in-nginx/
留言
張貼留言