Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

How to Use AddDefaultCharset UTF-8 in .htaccess

4 min read
29.09.2025

The AddDefaultCharset UTF-8 directive can be added to your .htaccess file to set UTF-8 as the default character encoding for your website or a specific directory. This ensures that browsers interpret your website text correctly, especially for international characters.

AddDefaultCharset UTF-8 in .htaccess
AddDefaultCharset UTF-8 — the one-line .htaccess fix for charset mismatches.

For the broader AddDefaultCharset reference and verification side, see AddDefaultCharset in .htaccess: Ensuring File Encoding. For the Apache modules that pair with this directive, see How to Enable and Configure mod_headers in Apache.

Steps to Add AddDefaultCharset UTF-8 in .htaccess

1

Locate or Create the .htaccess File

  • The .htaccess file is usually located in the root directory of your website (e.g., /public_html or /var/www/html).
  • If it does not exist, create a new file named .htaccess in the root directory.
2

Add the Directive

Open the .htaccess file in a text editor and add the following line:

AddDefaultCharset UTF-8
3

Save and Upload

  • Save the .htaccess file.
  • Upload it to your server root directory (if editing locally) using FTP or your hosting control panel.

How It Works

When AddDefaultCharset UTF-8 is included in .htaccess, the Apache server adds the following HTTP response header to all served files:

Content-Type: text/html; charset=UTF-8

This ensures that the browser interprets the content using UTF-8 encoding, even if no charset is specified in the HTML <meta> tag or other headers.

Testing the Configuration

Check the HTTP Headers

After adding the directive, verify that the Content-Type header includes charset=UTF-8.

Using Browser Developer Tools:

  1. Open your website in a browser.
  2. Right-click and select Inspect.
  3. Go to the Network tab and reload the page.
  4. Select the document (e.g., index.html) and check the Headers section.

Using Curl:

Run the following command:

curl -I http://yourdomain.com

Expected Output:

Content-Type: text/html; charset=UTF-8

Verify Rendering

  • Ensure that special characters (e.g., diacritics, emojis) are displayed correctly in the browser.
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

Best Practices for UTF-8 with .htaccess

Ensure File Encoding

Ensure that all files (HTML, PHP, CSS, etc.) are saved in UTF-8 encoding without a BOM (Byte Order Mark). Use editors like VS Code, Sublime Text, or Notepad++ to convert file encoding.

Use <meta> Tags for HTML

Add a <meta> tag to HTML documents to explicitly declare the encoding:

<meta charset="UTF-8">

Combine with PHP Headers

For dynamic content, set the charset in PHP:

header('Content-Type: text/html; charset=UTF-8');

Validate with W3C Validator

Check your website encoding using the W3C Validator.

Disabling the Default Charset

If you prefer to disable the default charset entirely and manage it through <meta> tags or PHP headers, use:

AddDefaultCharset Off

Troubleshooting

Issue Solution
Changes Not Reflected

Ensure that .htaccess is enabled on the server:

  • Check that AllowOverride is set to All in the Apache configuration:
  • <Directory /var/www/html>
    
        AllowOverride All
    
    </Directory>
  • Restart Apache after making changes:
  • sudo systemctl restart apache2   # Ubuntu/Debian
    sudo systemctl restart httpd     # CentOS/RHEL
File Encoding Mismatch If files are encoded in something other than UTF-8, update them to UTF-8 using a text editor.
Headers Still Show a Different Charset Check for conflicting configurations in the server or application (e.g., PHP scripts overriding .htaccess settings).

Adding AddDefaultCharset UTF-8 in .htaccess is an easy way to ensure all content served by your Apache server defaults to UTF-8 encoding. This helps with internationalization and prevents issues with displaying special characters.

Frequently asked questions
AddDefaultCharset sets a single default for every response Apache serves; AddCharset associates a charset with specific file extensions (you can mix UTF-8 for .html and Windows-1251 for legacy .txt). For modern sites where everything is UTF-8, AddDefaultCharset is the single line that does the job.
Three usual reasons: (1) the file on disk isn't actually UTF-8 — open it in a hex viewer and check for BOM/legacy bytes; (2) the application is sending its own Content-Type that overrides Apache (PHP's default_charset directive does this); (3) the page caches at a CDN that ignores Vary on Content-Type. Test with curl -I and trust the header field, not the rendered page.
No BOM for HTML. The HTML5 spec accepts it but old IE versions used to treat BOM as displayable, leading to mysterious blank rows at the top. UTF-8 doesn't need a BOM to be unambiguous (unlike UTF-16). Save "UTF-8 without BOM" in your editor.
Indirectly. Google reads Content-Type to know how to interpret your pages; if the announced charset doesn't match the actual content, Google indexes the mojibake version. So yes — getting this right is good for SEO, but the primary effect is users seeing correct text, search ranking is a side effect.
Related articles
Setting UTF-8 as the Default Charset in .htaccess
AddDefaultCharset windows-1251
AddDefaultCharset in .htaccess: Ensuring File Encoding