set default charset to UTF-8 encoding in apache

How To Set Default Charset to UTF-8 Encoding in Apache using htaccess

By default, Apache uses iso-8859-1 character encoding that represents the first 256 unicode characters. If your website needs to display international characters, then you need to change Apache character encoding to UTF-8. Otherwise, these characters will appear as unidentifiable symbols. In this article, we will look at how to set default charset to UTF-8 encoding in Apache using .htaccess.


How To Set Default Charset to UTF-8 Encoding in Apache using htaccess

Here are the steps to set default charset to UTF-8 encoding in Apache using htaccess.


1. Open htaccess file

Before proceeding, please enable mod_rewrite (.htaccess) in your Apache web server.

Open .htaccess file, typically located at /var/www/html/.htaccess

$ sudo vi /var/www/html/.htaccess

Also Read : How to Enable mod_rewrite in XAMPP, WAMP


2. Set Default Encoding to UTF-8

Add the following to .htaccess file.

AddDefaultCharset UTF-8

This will be applicable for all files served by Apache web server.

If you want to apply UTF-8 encoding only for specific file types, use the filesMatch directive.

<filesMatch "\.(html|css|js)$">
   AddDefaultCharset UTF-8
   DefaultLanguage en-US
</filesMatch>

Also read : How to Change Default Index Page


3. Restart Apache Web Server

Restart Apache web server to apply changes.

$ sudo service apache2 restart

That’s it. The default character encoding on your website will be changed to UTF8.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!