sthg sthg - 3 months ago 11x
PHP Question

Is it possible to set encoding for a single folder in Apache?

My server is set to UTF-8, but i'd like a specific folder and its contents to be encoded in Shift-JIS. I tried using .htaccess to set AddDefaultCharset Shift-jis but without luck.


Did you place your AddDefaultCharset directive in an htaccess located in the directory whose Charset you're trying to change? If not, please do so.

If you want all html files in that directory to have the charset, try

<FilesMatch "\.html?$">
    ForceType 'text/html; charset=Shift-jis'

If that doesn't work, you could set the HTTP header directly with the following directive (in the same htaccess)

<FilesMatch "\.html?$">
    Header add Content-Type "text/html; charset=Shift-jis"

You may need to add more FileMatch containers for other file types, and adjust the MIME type within the header (eg: "text/css" or "application/javascript" for .css and .js files)