欣怡嵉 發表於 2023-9-26 00:00:00

WordPress伪静态和中文标签支持配置方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
WORDPRESS博客站已经运行快一年了,在伪静态上一直很纠结,空间默认不支持伪静态,网上找了很多方法,用404错误页面来做伪静态,现在发现了问题了。google收录了,但百度不收录,因为百度在爬行页面的时候,文章链接都跳到了404页面,百度认为是错误页面,就不收录了。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
  为了做伪静态,让百度也收录,我终于不嫌麻烦,找空间商提供伪静态支持了。告诉空间商,我用的是wordpress程序,需要做伪静态。空间商的技术很快就帮忙搞定了。将Rewrite放到根目录,里面配置文件也有。之前我也在网上找 了伪静态规则的,我把httpd.ini放在根目录,好让技术知道伪静态规则是什么。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
伪静态规则代码:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div id="phpcode16" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
 <br>
# 3600 = 1 hour <br>
CacheClockRate 3600 <br>
RepeatLimit 32 <br>
# Protect httpd.ini and httpd.parse.errors files <br>
# from accessing through HTTP <br>
# Rules to ensure that normal content gets through <br>
RewriteRule /software-files/(.*) /software-files/$1  <br>
RewriteRule /images/(.*) /images/$1  <br>
RewriteRule /sitemap.xml /sitemap.xml  <br>
RewriteRule /favicon.ico /favicon.ico  <br>
# For file-based wordpress content (i.e. theme), admin, etc. <br>
RewriteRule /wp-(.*) /wp-$1  <br>
# For normal wordpress content, via index.php <br>
RewriteRule ^/$ /index.php  <br>
RewriteRule /(.*) /index.php/$1 </div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
把上面的规则代码复制到记事本里,改为httpd.ini,放到网站根目录。然后到网站后台设置固定链接。固定链接可以自定义。<br>
官方提供了如下一些参数。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div id="phpcode17" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
%year% 年份 <br>
%monthnum% 月份 <br>
%day% 日期 <br>
%hour% 小时 <br>
%minute% 分钟 <br>
%second% 秒 <br>
%postname% 文章名。 <br>
如文章名是“This Is A Great Post!”, <br>
那么“this-is-a-great-post”就是url中的文章名。 <br>
%post_id% 文章的ID <br>
%category% 目录 <br>
%author% 作者</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
我用的是文章的ID,%post_id%.html,如此设置,就是你看到的文章地址样式了。<br>
  伪静态配置好了,但还有问题哦。我们设置的文章标签通常是中文,但中文标签wordpress默认是不支持的,会跳到404页面去。要让其支持中文,还需要修改下程序文件。<br>
“wp-include”目录下的“class-wp.php”文件。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
第一步:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
找到<br>
$pathinfo = $_SERVER['PATH_INFO'];<br>
修改为:<br>
$pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], 'UTF-8', 'GBK');</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
第二步:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
找到<br>
$req_uri = $_SERVER['REQUEST_URI'];<br>
修改为:<br>
$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], 'UTF-8', 'GBK');</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
如此修改,wordpress就支持中文的标签了。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
  是不是一下畅快多了?</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
  注意:如果你的博客目录或根目录装有其他程序,上面伪静态的“httpd.ini”会导致把你的访问都转回博客的首页,从而导致不能访问和你博客同一目录或根目录的程序,如果有谁有更好的方法,求分享!</p>
頁: [1]
查看完整版本: WordPress伪静态和中文标签支持配置方法