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

Setting UTF-8 as the Default Charset in .htaccess

3 min read
27.04.2026

Using .htaccess, you can set UTF-8 as the default character encoding for your website. This ensures that all content served by your server uses the UTF-8 encoding, which is a modern standard and supports a wide range of characters and languages.

Set UTF-8 Default Charset in .htaccess
AddDefaultCharset UTF-8 for multilingual sites.

For the broader AddDefaultCharset reference, see AddDefaultCharset in .htaccess: Ensuring File Encoding, How to Use AddDefaultCharset UTF-8 in .htaccess, and How to Use AddDefaultCharset in Apache.

Steps to Set UTF-8 as the Default Charset

1

Open or Create .htaccess File

  • Navigate to the root directory of your website (e.g., /public_html or /var/www/html).
  • Look for an existing .htaccess file. If it does not exist, create one.
2

Add the Directive to .htaccess

Add the following line to the .htaccess file:

AddDefaultCharset UTF-8

This will set the default charset for all content served from this directory and its subdirectories.

3

Save and Upload

  • Save the .htaccess file.
  • If editing locally, upload it to your server using an FTP client or file manager in your hosting control panel.

Testing the Configuration

Verify HTTP Headers

Check if the Content-Type header includes charset=UTF-8.

Using Browser Developer Tools:

  1. Open your website in a browser.
  2. Inspect the page (Right-click > Inspect).
  3. Go to the Network tab, reload the page, and select the document.
  4. Check the Headers section for Content-Type.

Expected output:

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

Using Curl:

Run the following command:

curl -I http://yourdomain.com

Expected output:

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

Verify in the Browser

  • Open your website and ensure special characters (e.g., diacritics, emojis) display correctly.
  • Include a sample text with special characters to test.

Adding a Fallback <meta> Charset

For additional safety, explicitly declare the charset in your HTML files using the <meta> tag:

<meta charset="UTF-8">

This ensures the browser uses UTF-8 encoding even if the server headers are not received correctly.

Common Issues and Solutions

Issue Solution
.htaccess Changes Not Working Ensure .htaccess is enabled in the Apache configuration (AllowOverride All).
Encoding Mismatch Ensure all files are saved as UTF-8 without BOM.
Garbled Text in Browser Verify file encoding and ensure <meta charset="UTF-8"> is present in HTML.
Conflicting Headers Check if other server configurations (e.g., PHP headers) override the .htaccess settings.

Example .htaccess File

Below is an example of a complete .htaccess file with UTF-8 as the default charset:

# Set the default charset to UTF-8

AddDefaultCharset UTF-8



# Enable additional headers for security (optional)

<IfModule mod_headers.c>

    Header set Content-Type "text/html; charset=UTF-8"

</IfModule>
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

Best Practices

1. Save Files as UTF-8

Ensure all files (HTML, PHP, CSS, JavaScript, etc.) are encoded in UTF-8 without BOM (Byte Order Mark). Use editors like Notepad++, VS Code, or Sublime Text to check and convert file encodings.

2. Set Charset in Dynamic Content

If you use PHP, add this line at the top of your scripts:

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

3. Test Across Browsers

Test your website in multiple browsers to confirm consistent behavior.

4. Use UTF-8 for Databases

Ensure your database and tables use utf8mb4 encoding for full UTF-8 support.

By setting AddDefaultCharset UTF-8 in .htaccess, you ensure consistent and correct rendering of multilingual and special characters across your website.

Frequently asked questions
AddDefaultCharset UTF-8 in .htaccess — that's it. Pair it with AddCharset UTF-8 .html .css .js if you want belt-and-braces explicit declarations. For UTF-8 emoji support specifically, the database also needs to be utf8mb4.
No — only the announcement changes, not the bytes on disk. Pages saved as ISO-8859-1 still render as mojibake when announced as UTF-8. Either convert the files (iconv -f ISO-8859-1 -t UTF-8 in.html > out.html) or override per-file with AddCharset ISO-8859-1 .legacy.
WordPress, Joomla, and Drupal all emit their own Content-Type via PHP headers. .htaccess AddDefaultCharset is overridden by PHP's default_charset on dynamic pages. Set both to UTF-8 to be consistent — on static assets only AddDefaultCharset applies.
curl -I https://yourdomain.com/page.html and check the Content-Type line. You should see Content-Type: text/html; charset=UTF-8. If you see no charset at all, .htaccess isn't being read (check AllowOverride). If you see a different charset, PHP or another layer is overriding.
Related articles
How to Use AddDefaultCharset UTF-8 in .htaccess
AddDefaultCharset in .htaccess: Ensuring File Encoding
AddDefaultCharset windows-1251