Set Default Character Set using Htaccess

  • Avinash
  • 1
  • Aug 09, 2011
  • Web Server

Character set defines list of the characters recognized by the hardware or the software. Each character is represted by the number.

For example ASCII is the character set which contains the character from 0 to 127 to control all english character plus some special characters. ISO is the other character set is similar to ASCII but it includes some additional characters for European.

So to instruct the browser to which character set to use for rendering the page we need to set the character set of the webpage.

We can set this character set using by just one line of code.

Place below code in you .htaccess file:

# use utf-8 encoding for anything served text/plain or text/html AddDefaultCharset utf-8 # This applies to all the content serverd by the web server.
# use utf-8 encoding for anything served text/plain or text/html
AddDefaultCharset utf-8
# This applies to all the content serverd by the web server.

If you want to set the specific character set for certain types of files then use the below code in you .htacess file.

# force utf-8 for a number of file formats AddCharset utf-8 .html .css .js .xml .json .rss
# force utf-8 for a number of file formats
AddCharset utf-8 .html .css .js .xml .json .rss

Note: Some basic and most used character sets are ASCII, ISO, UTF-8.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • Gamaliel

    Thanks, it worked for me