Home > Wordpress > wordpress 中文 url 的问题

wordpress 中文 url 的问题

先前一篇文章介绍了一个wordpress iis 下 ISAPI_Rewrite的一个新规则
如果大家用了那个规则,可以看到英文的url不会有任何问题,但含有中文的会返回404页面。
服务器是windows 2003的,默认字符集是gbk编码的,前面的文章有介绍这类的文章
比如
http://www.humker.com/2008/05/17/character-set/
专门介绍了字符集的区别
php用的字符集是utf-8的,这样与服务器的交互就会有问题。
如果是乱码文章就不会回显变量值,以前一个ecms的批量插入软件的插件就是这个问题,读取不了中文目录。
下面的文章解决了中文url的问题,当然不仅仅是tag的问题,因为她的方法是让所有的url重新编码。
如何让WordPress的tag支持中文
http://www.bolarn.com/index.php/2008/01/26/52/
这篇文章主要改动的是
wp-includes\classes.php文件
找到

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'];

替换为

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

原文处css有问题不能完全显示,这里又贴了一遍。

另外一个就是替换一个文件 taxonomy.php

google搜索“wordpress-26-chinese-tags-bug-fixed.zip”,本站就不提供下载了。

这个文件有望在2.6.1里修正,主要目的是中文 tag 页回显 title 有问题。

另外如果使用本站新的url rewrite规则,还要修改一个文件

具体参考这个文章
http://trac.wordpress.org/ticket/5682

if ( empty( $_SERVER['REQUEST_URI'] ) )

替换为

if ( empty( $_SERVER['REQUEST_URI'] ) || substr( $_SERVER['SERVER_SOFTWARE'], 0, 13 ) == ‘Microsoft-IIS’ )

Categories: Wordpress Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).