windows主机wordpress用404伪静态,中文tag404和搜索翻页错误


在小波初把廿壴(ganxb2)博客 - 小波个人分享圈子网站上线时,曾就为了windows主机下WP做404伪静态大费周章,花了不少时间,但是一直都没有真正把404伪静态这个问题给处理完美。

一方面因为主机是windows的,另一方面是因为小波的博客是在2级目录,所以利用404处理WP博客的URL伪静态成了小波遇到最棘手的问题,直到现在因为用404做URL伪静态分享圈子网站上还遗留不少的BUG问题无法处理,当然这些BUG都是针对分享圈子的。

o(∩_∩)o哈哈


🧐wordpress伪静态后TAG中文标签404错误或者链接出错解决办法

  1. 找到博客里的wp-includes文件夹下的class-wp.php

  2. 搜索如下关键字:if ( isset($_SERVER['PATH_INFO']) ) ,应该会有如下代码:

    1
    2
    3
    4
    5
    6
    7
    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'];

    修改为:

    1
    2
    3
    4
    5
    6
    7
    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’);

🤔wordpress伪静态后搜索翻页错误解决办法

如果博客搜索有分页不会跳第2页而是直接跳到博客首页,其实这个问题不麻烦,在前面我提到的那篇文章中,小波曾说用以下这段代码来实现404伪静态

1
2
3
4
5
6
7
<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ‘:80′)+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];

include(‘index.php’);
?>

修改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// This is the default file for the site. Usually index.php
$default = ‘index.php’;

// The name of this file.
// Set this value for the URL in Custom Error Properties of your website in IIS.
// Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >
// 404 & 404;2 & 404;3 > URL (Requires a ‘/’ prefix in IIS).
$thisfile = ‘wp-404.php’;

$_SERVER['ORIG_PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_TRANSLATED']);
$_SERVER['SCRIPT_FILENAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_FILENAME']);
$_SERVER['ORIG_PATH_INFO'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_INFO']);
$_SERVER['SCRIPT_NAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_NAME']);
$_SERVER['PHP_SELF'] = str_replace($thisfile, $default, $_SERVER['PHP_SELF']);
$_SERVER['PATH_INFO'] = false;
$qs =& $_SERVER['QUERY_STRING'];
$ru =& $_SERVER['REQUEST_URI'];
$pos = strrpos($qs, ‘://’);
$pos = strpos($qs, ‘/’, $pos + 4);
$_SERVER['URL'] = $ru = substr($qs, $pos);
$qs = trim(stristr($ru, ‘?’), ‘?’);

// Required for WordPress 2.8+
$_SERVER['HTTP_X_ORIGINAL_URL'] = $ru;

// Fix GET vars
foreach ( $_GET as $var => $val ) {
if ( substr($var, 0, 3) == ’404′) {
if ( strstr($var, ‘?’) ) {
$newvar = substr($var, strpos($var, ‘?’) + 1);
$_GET[$newvar] = $val;
}
unset($_GET[$var]);
}
break;
}
include($default);
?>

请注意上面这段代码中 $thisfile = ‘wp-404.php’;

如果您直接复制代码注意改成您自己的404页面名字,或者您可以选择下载小波已整理打包的压缩文件。


😚windows主机wp博客404伪静态404.php百度云下载地址

wordpress用404伪静态,中文tag404和搜索翻页错误

点我去廿壴(ganxb2)博客的百度云下载


PS:有任何不明白或者需要小波帮忙的地方请留言告之


THE END
windows主机wordpress用404伪静态,中文tag404和搜索翻页错误
https://blog.ganxb2.com/60240.html
作者
chopin gump chopin gump
许可协议
小尾巴
Stay Hungry, Stay Foolish「求知若饥, 虚心若愚」 — 廿壴(ganxb2)
微信

微信

支付宝

支付宝

🕐如果评论显示“刷新”无法加载,过一会再来康康~🕢 _(≧∇≦」∠)_ (填写常用邮箱即可快速收到回复通知~)