WordPress中文Tag标签点击后出现404页面的解决方案

技术流评论2,561阅读模式

中文标签点击后出现404常见原因多为UTF8和GBK编码没有被正确识别的问题,另有一部分是伪静态规则设置错误。

就5.2.2来说,解决这个问题两种办法:文章源自原紫番博客-https://www.yuanzifan.com/54128.html

1.简单粗暴,改标签别名:文章源自原紫番博客-https://www.yuanzifan.com/54128.html

文章源自原紫番博客-https://www.yuanzifan.com/54128.html

2.修改代码,一劳永逸文章源自原紫番博客-https://www.yuanzifan.com/54128.html

打开wp-includes/class-wp.php文章源自原紫番博客-https://www.yuanzifan.com/54128.html

找到下面这行代码:文章源自原紫番博客-https://www.yuanzifan.com/54128.html

$pathinfo  = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] :

将其修改为:文章源自原紫番博客-https://www.yuanzifan.com/54128.html

$pathinfo = isset( $_SERVER['PATH_INFO'] ) ? mb_convert_encoding($_SERVER['PATH_INFO'], 'utf-8', 'GBK') : '';

再找到如下代码——就在上一行附近,各种版本有所不同,大概在160~190行之间。文章源自原紫番博客-https://www.yuanzifan.com/54128.html

list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] );

将代码替换为:文章源自原紫番博客-https://www.yuanzifan.com/54128.html

list( $req_uri ) = explode( '?', mb_convert_encoding($_SERVER['REQUEST_URI'], 'utf-8', 'GBK') );

这里用到了PHP的mb_convert_encoding函数,其实就是转码。把UTF8转为GBK。在显示出来,语法如下:
mb_convert_encoding($filename, "GB2312", "UTF-8");//将utf-8 格式的filename的转 gb2312文章源自原紫番博客-https://www.yuanzifan.com/54128.html

需要注意的是,这个需要PHP的 mbstring扩展。所以,如果你修改后报错,记得加载这个扩展。

 

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证