Using Django to implement webpage URLs using Chinese pinyin as the SEO optimization Implementation Method

Source: Internet
Author: User

Pinyin, as the SEO optimization, is mainly used by Chinese users, while pinyin Seo optimization is mainly used in the following scenarios:

1. Pinyin domain name.

For Chinese, Pinyin domain names are easier to remember than English domain names. A simple and memorable domain name is half the success of a startup website. For example, "Baidu", "Taobao", "Xunlei", "Douban", and other double-byte pinyin domain names are easy to remember and spread, which is a good example of domain names, it has made great contributions to promoting the development of these websites. Therefore, it is very important to carefully select a good pinyin domain name.

For a webmaster, it is better to choose a domain name that is easy to optimize than to try to find a domain name in the world. The Optimization Method for a large brand site is different from that for a small personal Webmaster. The main site tends to be optimized with the internal page, and the homepage mainly determines the ranking of the brand. For example, Tudou, Youku, starting point, hongcuff, Jinjiang, and other big sites, their domain names need to consider the brand effect and make it easy for users to remember. The personal webmaster has a low investment and a low weight. The best strategy is to make full use of the homepage weight. In this case, the advantages of Pinyin domain names are very obvious.

Pinyin domain names can be divided into two categories, one is the domain name of the first letter of the Chinese character, such as xuanhuan novel network (xhxsw), the novel reading network (xsydw), and the other is the full Chinese Character spelling, such as xuanhuanxiaoshuowang, xiaoshuoyueduwang. If you have registered both the first and all pinyin matches, you can find a domain name, such as www.xiaoshuoyd.com. As the Domain Name of the novel reading network, the search volume of the word Xiaoshuo is okay, it is also included in the domain name. Therefore, even if there is no complete pinyin domain name, it can be replaced with a similar one, but the domain name should start with the required keyword. (This section is organized from the network .)

2. pinyin link. use the Chinese character title pinyin as the URL link for the article URL. Seo can be optimized when users use pinyin search. there are two types of Pinyin links, one is the first Chinese character and the other is the full Chinese Character pinyin.

This article mainly discusses how to use Chinese pinyin as the SEO optimization method to implement webpage link URLs using Django.

To use Chinese characters as URLs, the key and difficulty lies in converting Chinese characters into pinyin. Therefore, this article mainly considers how to convert Chinese characters into Pinyin and use them in Django.

2.1 use python to convert Chinese characters to PinYin

Use a dictionary and Conversion Program. on the Internet, a person named Caocao made a python Chinese character to PinYin module. for the original program, refer to this article: a python applet that converts GBK Chinese characters into pinyin.
Http://blog.csdn.net/nethermit/article/details/156193 And here: http://www.cnblogs.com/caocao/archive/2005/09/13/235705.html, this layout is better.

Convert.txt is a dictionary, but the download is not provided in the author's blog. I searched through the Internet and downloaded the entire compressed package from other sources, including the dictionary and Conversion Program. this program is based on GBK. To divide Chinese characters into high/low bits, most people cannot understand it. I made some improvements to convert the dictionary into UTF-8, because the code used in Django is UTF-8. then his program has been improved to process Unicode characters, because Unicode characters only need to process one character and do not need to be split into two halves.

My convert program:

# -*- coding: utf-8 -*- # ------------------------------------------------------------# Script   Name: convert.py# Creation Date: 2010-09-21  02:12# Last Modified: 2011-11-12 18:38:13# Copyright (c)2011, DDTCMS Project# Purpose: This file used for DDTCMS Project# ------------------------------------------------------------######################################   Written by caocao               ##   Modified by huyoo353@126.com    ##   caocao@eastday.com              ##   http://nethermit.yeah.net       ####################################### python.import sys,osimport reimport stringclass CConvert:def __init__(self):self.has_shengdiao = Falseself.just_shengmu  = Falseself.spliter = '-'"Load data table"try:fp=open(os.path.join(settings.PROJECT_DIR, 'utils', 'convert-utf-8.txt'))except IOError:print "Can't load data from convert-utf-8.txt\nPlease make sure this file exists."sys.exit(1)else:self.data=fp.read().decode("utf-8")# decoded data to unicodefp.close()def convert1(self, strIn):"Convert Unicode strIn to PinYin"length, strOutKey, strOutValue, i=len(strIn), "", "", 0while i<length:code1 =ord(strIn[i:i+1])if code1>=0x4e02 and code1<=0xe863:strTemp   = self.getIndex(strIn[i:i+1])if not self.has_shengdiao:strTemp  = strTemp[:-1]strLength = len(strTemp)if strLength<1:strLength=1strOutKey   += string.center(strIn[i:i+1], strLength)+" "strOutValue += self.spliter + string.center(strTemp, strLength) + self.spliterelse:#ascii code;strOutKey+=strIn[i:i+1]+" "strOutValue+=strIn[i:i+1] + ' 'i+=1##############################txlist = utf8String.split()#out=convert.convert(utf8String)#l=[]#for t in map(convert.convert, txlist):#l.append(t[0])#v = '-'.join(l).replace(' ','').replace(u'--','-').strip('-')#############################return [strOutValue, strOutKey]def getIndex(self, strIn):"Convert single Unicode to PinYin from index"if strIn==' ':return self.spliterif set(strIn).issubset("'\"`~!@#$%^&*()=+[]{}\\|;:,.<>/?"):return self.spliter # or return ""if set(strIn).issubset("-—!##%%&&()*,、。:;?? @@\{{|}}~~‘’“”《》【】++==×¥·… ".decode("utf-8")):return ""pos=re.search("^"+strIn+"([0-9a-zA-Z]+)", self.data, re.M)if pos==None:return strInelse:if not self.just_shengmu:return pos.group(1)else:return pos.group(1)[:1]def convert(self, strIn):"Convert Unicode strIn to PinYin"if self.spliter != '-' and self.spliter !='_' and self.spliter != '' and self.spliter != ' ':self.spliter = '-'pinyin_list=[]for c in strIn :pinyin_list.append(self.getIndex(c))pinyin=''for p in pinyin_list:if p==' ':pinyin+= self.splitercontinueif len(p)<2:# only shengmu,just get one char,or number#if p.isdigit():#pinyin += p + ' '#else:#pinyin += p + ' 'pinyin += p + ' 'else:if not self.has_shengdiao: p = p[:-1]pinyin += self.spliter + p + self.spliterpinyin = pinyin.replace(' ','') \.replace(self.spliter+self.spliter,self.spliter) \.strip(self.spliter+' ').replace(self.spliter+self.spliter,self.spliter)return pinyin

In the code above, the convert1 () function was originally provided by the author and I changed its name. I replaced the original function name with the convert I wrote and changed the dictionary file to UTF-8 encoded. so it should be simpler.

The convert function provides

Self. has_shengdiao = false
Self. just_shengmu = false
Self. spliter = '-'
Used to configure parameters. has_shengdiao is used for converting Chinese characters into pinyin,

Just_shengmu converts a string of Chinese characters into a string of the first character to false.

Spliter is used to separate Chinese characters. if it is null, the conversion results are not separated by spliter. By default, "-" (horizontal line is used to connect Chinese pinyin, because W3C recommends using-as a hyphen in URLs, instead of the underscore _ to connect to the string, because when the underline is used as the link connection string, the URL seems to have been broken in the address bar, and _ underlines are often invisible .)

Dictionary files cannot be provided by this blog, but you can search and download the original dictionary, and then use the software that supports UTF-8 conversion.

Contact me if necessary.

--------------------------

The supplementary dictionary from is as follows, which has been converted to UTF-8 format without Bom.

File Name: convert-utf-8.txt
Address: http://www.kuaipan.cn/file/id_41002888838774807.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.