Is there some way to implement the function of mod_encoding in Apache httpd?

agentzh agentzh at
Wed Jun 15 16:05:19 MSD 2011

On Tue, Jun 14, 2011 at 4:01 PM, sunjipeng_neu <nginx-forum at> 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) {
       rewrite ^ $new_uri;

This *should* work out of the box if you have compiled the ngx_iconv
module into your nginx server:

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,

More information about the nginx mailing list