diff --git a/modules/base/template.go b/modules/base/template.go
index 1442bf0e8..bc69bb3b3 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -55,6 +55,9 @@ func ShortSha(sha1 string) string {
 func DetectEncoding(content []byte) (string, error) {
 	detector := chardet.NewTextDetector()
 	result, err := detector.DetectBest(content)
+	if result.Charset == "ISO-8859-1" {
+		return setting.AnsiCharset, err
+	}
 	return result.Charset, err
 }
 
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 2364c313a..896e60ad1 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -84,6 +84,7 @@ var (
 	// Repository settings.
 	RepoRootPath string
 	ScriptType   string
+	AnsiCharset  string
 
 	// UI settings.
 	IssuePagingNum int
@@ -312,6 +313,7 @@ func NewConfigContext() {
 		RepoRootPath = path.Clean(RepoRootPath)
 	}
 	ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
+	AnsiCharset = sec.Key("ANSI_CHARSET").MustString("ISO-8859-1")
 
 	// UI settings.
 	IssuePagingNum = Cfg.Section("ui").Key("ISSUE_PAGING_NUM").MustInt(10)