How can I map the uri to local file path between different charset?
Such as, the uri is encode with UTF-8 but my local file system charset
is GBK or EUCKR or EUCJP.
So, the “404 not found” will happen cause the path name can’t matched.
Posted at Nginx Forum:
Why not unify your local file name encoding to UTF-8?
2011/6/14 sunjipeng_neu [email protected]
On Tue, Jun 14, 2011 at 4:01 PM, sunjipeng_neu [email protected]
wrote:
How can I map the uri to local file path between different charset?
Such as, the uri is encode with UTF-8 but my local file system charset
is GBK or EUCKR or EUCJP.
Here’s an example for utf-8 → euc-kr:
location / {
set_iconv $new_uri $uri from=utf8 to=euc-kr;
if ($uri = $new_uri) {
break;
}
rewrite ^ $new_uri;
}
This should work out of the box if you have compiled the ngx_iconv
module into your nginx server:
https://github.com/calio/iconv-nginx-module
It’s not the most efficient though because set_iconv will always be
called twice. Here’s a modified but slightly complicated way:
location / {
}
location ~ ‘^/euc-kr(/.+)’ {
set $path $1;
set_iconv $new_path $path from=utf8 to=euc-kr;
rewrite ^ $path;
}
But now it requires you to invoke /enc-kr/foo/bar.html instead of the
original /foo/bar.html.
If you want the file content sent to the content to be converted to
UTF-8, you can use the iconv_filter directive provided by the
ngx_iconv module.
Hope this helps,
-agentzh