Web-server – htaccess redirect changes encoding of HTML response

.htaccessutf-8web-server

I've set Apache 2.4 server to AddDefaultCharset utf-8 in httpd.conf and my .htaccess file redirects all non-www and http to https://www.example.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https//www.example.com/$1 [R=301,L,NE]

If I look at HTTP response header, only traffic sent to https://www.example.com generates a UTF-8 response.
The non-www and http traffic respond with ISO-8859-1 charset.

Anyone know how to ensure all URL-redirect HTTP responses are in UTF-8?

Best Answer

This would seem to be default behaviour, since the Apache redirect response is encoded as ISO-8859-1. However, Apache does allow you to suppress the charset parameter in the response by setting the suppress-error-charset environment variable:

# set desired env variable to suppress iso-8859-1 charset
SetEnvIf Host ^ suppress-error-charset

However, it cannot be changed to a different charset.

Reference: