[WordPress] WordPress Chinese tags garbled many solutions

Source: Internet
Author: User
Tags website server

Try the following methods, because the website server of onebody uses win2003 + IIS to finally choose between solution 1 and solution 2. If the solution fails, the results will be the same for several times, the last step is to use solution 2!WordPress can be correctly parsed. Cause: This is caused by URL Encoding Problems. For link 1 above, this is a pathinfo, and for Link 2, this is a querystring. It turns out that for pages in the UTF-8, both IE and FF will correctly send pathinfo and querystring (unlike some articles that say they have incorrect responses under different settings ), however, on the server side, IIS will convert pathinfo to GBK encoding, resulting in errors. Therefore, you only need to switch back to this type of problem in windows. However, Apache does not support Chinese pathinfo in Linux, either modify Apache or, just like me, Linux Hosts cannot use permalink in Chinese. Therefore, we can only find a detour. Solution Analysis: first, the conversion encoding principle is that IIS will convert the UTF-8 in pathinfo into GBK, and querystring won't convert, so in order to use permalink, use the following method: open WP-nodes des/classes. PHP file,

if ( isset($_SERVER['PATH_INFO']) )  $pathinfo = $_SERVER['PATH_INFO'];else  $pathinfo = '';$pathinfo_array = explode('?', $pathinfo);$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);$req_uri = $_SERVER['REQUEST_URI'];

Change

if ( isset($_SERVER['PATH_INFO']) )  $pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], "UTF-8", "GBK");else  $pathinfo = '';$pathinfo_array = explode('?', $pathinfo);$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], "UTF-8", "GBK");

Limitation: it is only valid for Windows hosts and must be IIS hosts in windows. 2. Modify WP-nodes des/rewrite. PHP is the most common method on the Internet. The principle is that WordPress does not use tags when using permalink for other content, but uses querystring mode of link 2 to send Chinese encoding:

 function get_tag_permastruct() {if (isset($this->tag_structure)) {return $this->tag_structure;}if (empty($this->permalink_structure)) { //-----this line need change------$this->tag_structure = '';return false;}

Change row 5th

if (!empty($this->permalink_structure)) {

Limitation: permalink does not play a "beautiful" role. If you cannot modify the WP file, you cannot. 3. Modify the tag base principle. You only need to enable the permalink function of WordPress and ignore the tag. Is it feasible to trick WordPress into displaying permalink in the format of link 2? This is feasible because WordPress can customize the permalink format: Enter/In the WordPress settings-permalinks-tag base /? Tag = Note: "" is not uncommon. The original document is incorrectly referenced. In addition, every time you input "", WP will be escaped as "/" again, so "" will be doubled every time you click submit, and "//" will be clicked twice "//", so don't try more. It's right once. The result of this method is to make the link look like this.

Www.example.com /? Tag =/Chinese/

The excessive slashes have no effect on the server, or are considered as querystring. The limitation is that the link is getting worse. What's more fatal is that in the sitemap generated by the plug-in, the tag link will become an incorrect form. If you care about sitemap, please do not use this method, unless you cannot modify your own rewrite. PHP file. However, when you use WP-supercache or similar cache plug-ins, it will add its own rewrite rules, and all requests will be judged by yourself first, it is not in the cache or does not comply with the cache rules before being handled by WordPress. But the problem is that it does not support Chinese URL resolution, even if it is querystring. So we must bypass it. This is the rewrite rule added by WP-supercache in the. htaccess file.

RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_METHOD} !=POSTRewriteCond %{QUERY_STRING} !.*s=.*RewriteCond %{QUERY_STRING} !.*p=.*RewriteCond %{QUERY_STRING} !.*attachment_id=.*RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$RewriteCond %{HTTP:Accept-Encoding} gzipRewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -fRewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]RewriteCond %{REQUEST_METHOD} !=POSTRewriteCond %{QUERY_STRING} !.*s=.*RewriteCond %{QUERY_STRING} !.*p=.*RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*RewriteCond %{QUERY_STRING} !.*attachment_id=.*RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -fRewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]

What we need to do is not let it judge the link of the Chinese tag, in two rewritecond % {request_method }! = Add the following sentence after post:

RewriteCond %{QUERY_STRING} !.*tag=.*

The meaning is that if querystring contains the tag, do not parse it (to the next rule, it is WordPress index. php in general ). Conclusion: On Windows + IIS hosts, solution 1 can perfectly solve the Chinese tag problem. On Linux + Apache hosts, permalink cannot be used unless Apache is modified, otherwise, you can bypass solution 2 and solution 3. Solution 2 is a relatively recommended method, but when used with WP-supercache, you need to add a rule in the. htaccess file that does not process tag links.

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.