本博客系宁波SEO联盟资深成员 seolm.org

wordpress伪静态后包含中文词的url显示找不到内容(解决方法)

用wordpress伪静态规则后,我们点击中文标量的文章链接时说找不到网址。

这是因为:WP的编码为utf-8,而URL中Slug编码为gbk。然后WP取得文章Slug后,通过它来查找文章就会找不到!因为编码不同呀。修改wp-include/classes.php中(44-50行)。

 更改方法:
   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'];

替换为下(转换$_SERVER['PATH_INFO']和$_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’);

这个操作的意思就是:将Slug的编码由GBK转换为utf-8(您也可以用iconv,或是其它的函数来代替mb_convert_encoding)。

本博客即为演示。

wordpress伪静态与去掉index.php修改方法

没有官方的代码。不完美,寻找中。

2010-2-28 2.9版本,测试成功。

[ISAPI_Rewrite]
# Defend your computer from some worm attacks
#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
RewriteRule /tag/(.*) /index\.php\?tag=$1
RewriteRule /software-files/(.*) /software-files/$1 [L]
RewriteRule /images/(.*) /images/$1 [L]
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

上面的代码使用后,tag页面不正常。因为编码问题。

解决办法见:wordpress伪静态后包含中文词的url显示找不到内容(解决方法)

Hello world!

欢迎使用 WordPress 。这是系统自动生成的演示文章。编辑或者删除它,开始您的博客!

返回顶部