# Is there some way to implement the function of mod\_encoding in Apache httpd?

**URL:** <https://www.ruby-forum.com/t/is-there-some-way-to-implement-the-function-of-mod-encoding-in-apache-httpd/208290>\
**Category:** NGINX\
**Created:** [June 14, 2011, 10:01am UTC](https://www.ruby-forum.com/t/is-there-some-way-to-implement-the-function-of-mod-encoding-in-apache-httpd/208290 "2011-06-14T10:01:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 14, 2011, 10:01am UTC](https://www.ruby-forum.com/t/is-there-some-way-to-implement-the-function-of-mod-encoding-in-apache-httpd/208290/1 "2011-06-14T10:01:44Z")

</div>

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:

> **[Is there some way to implement the function of mod\_encoding in Apache httpd?](https://forum.nginx.org/read.php?2,206658,206658#msg-206658)**
>
> 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.

---

<div class="post-metadata">

**Author:** ![sunjipeng\_neu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@sunjipeng\_neu](https://www.ruby-forum.com/u/sunjipeng_neu)\
**Post date:** [June 15, 2011, 12:50pm UTC](https://www.ruby-forum.com/t/is-there-some-way-to-implement-the-function-of-mod-encoding-in-apache-httpd/208290/2 "2011-06-15T12:50:50Z")

</div>

Why not unify your local file name encoding to UTF-8?

2011/6/14 sunjipeng\_neu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sunjipeng\_neu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@sunjipeng\_neu](https://www.ruby-forum.com/u/sunjipeng_neu)\
**Post date:** [June 15, 2011, 2:15pm UTC](https://www.ruby-forum.com/t/is-there-some-way-to-implement-the-function-of-mod-encoding-in-apache-httpd/208290/3 "2011-06-15T14:15:35Z")

</div>

On Tue, Jun 14, 2011 at 4:01 PM, sunjipeng\_neu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
