Web Server

Set Default Character Set using Htaccess

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:

[cc lang=”apache”]
# 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.
[/cc]

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

[cc lang=”apache”]
# force utf-8 for a number of file formats
AddCharset utf-8 .html .css .js .xml .json .rss
[/cc]

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

Shares:
  • Gamaliel
    Gamaliel
    December 18, 2011 at 2:49 pm

    Thanks, it worked for me

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *