The Chinese link in the WordPress static post tag cannot find the page Solution

Source: Internet
Author: User

From: http://www.li.cm/news/2011/04/17/wordpress-%E8% AE %BE%E7%BD% AE %E9%9D%99%E6%80%81%E5%90%8E%E6%A0%87%E7%AD%BE%E4%B8%AD%E4%B8%AD%E6%96%87%E9%93%BE%E6%8E%A5%E6%89%BE%E4%B8%8D%E5%88%B0%E9%A1%B5%E9%9D%A2%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9.html

On the Windows IIS host, set the WordPress tag. When you click Enter at the front-end, you will find that the page cannot be opened and jumps to the 404 error page, causing Encoding Problems.

So we need to convert it into UTF-8 and GBK encoding, the following three solutions are recommended:
1. Modify WP-uplodes/Rewrite. php

This 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:

If (empty ($ this-> permalink_structure ))
{// ----- This line need change ------
Change

If (! Empty ($ this-> permalink_structure ))
{

2. If you are using a Windows host, you can do the following:

IIS converts the UTF-8 in pathinfo to GBK, while querystring does not, so to use permalink, use the following method:
Open the WP-nodes des/classes. php file. Rows from 154 to 159

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 ");

The disadvantage of such issuance is that it is only valid for Windows hosts and must be IIS hosts in windows.

3. Modify the tag Base

The principle is the same as above, as long as WordPress continues to ignore tags after the permalink function is enabled. 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:
In the WordPress settings? (Fixed Link) permalinks? (TAG prefix) Fill in tag Base
/? Tag =
Note that "" cannot be missing. The original document is incorrectly quoted. In addition, every time you input "", WP will be escaped as "" again, so "" will be doubled for each point submission, and "\" will be clicked twice, so do not add more points, this is the right time.
The result of this method is to make the link look like this.
Www. Li. CM /? 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 on
Rewritebase/
Rewritecond % {request_method }! = Post
Rewritecond % {QUERY_STRING }!. * S = .*
Rewritecond % {QUERY_STRING }!. * P = .*
Rewritecond % {QUERY_STRING }!. * Attachment_id = .*
Rewritecond % {QUERY_STRING }!. * WP-subpipeline-Manager = .*
Rewritecond % {http_cookie }! ^. * (Comment_author _ | WordPress | WP-postpass _). * $
Rewritecond % {http: Accept-encoding} Gzip
Rewritecond % {document_root}/WP-content/Cache/supercache/% {http_host}/$1/index.html.gz-F
Rewriterule ^ (. *)/WP-content/Cache/supercache/% {http_host}/$1/index.html.gz [l]
Rewritecond % {request_method }! = Post
Rewritecond % {QUERY_STRING }!. * S = .*
Rewritecond % {QUERY_STRING }!. * P = .*
Rewritecond % {QUERY_STRING }!. * WP-subpipeline-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-F
Rewriterule ^ (. *)/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 ).

PS: For Windows + IIS hosts, solution 1 can perfectly solve the Chinese tag problem. For Linux + Apache hosts, permalink cannot be used in Chinese unless Apache is modified, otherwise, only solution I and solution III will be used for detour. Solution 1 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.