缓行 發表於 2023-11-29 00:00:00

WordPress在IIS服务器上的伪静态设置方法(解决中文URL无法访问问题)

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
我们都知道WordPress程序很强大,对搜索引擎优化很友好,但是有一点可能有些人还不是很清楚,对于WordPress这样一款开源程序来 说,它本身就是在Linux/Apache平台中开发,先天上与其结合得比较紧密,因此,如果可能的话,选择Linux/Apache平台应该是第一选 择。尽管WordPress可以在Windows/iis平台中安装使用,但存大许多不足,其实中致命的一点便是IIS本身不支持Mod_Rewrite 功能,而这将会给博客的维护、管理、SEO优化带来很多麻烦。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
由于IIS不支持Mod_Rewrite,因此,Wordpress便无法实现标准的、简洁的Permalinks,而只能采取在Url中包含“index.php“的替代方案(如SEO探索的权益之计中所探讨的那样);所以无法实现真正的伪静态功能。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
经过几天的努力找答案终于搞定了Wordpress在win/IIS下伪静态的功能,虽然网上有利用404.php页面来实现的方法,但终归没有这种自然的好。今天就给大家分享一下,首先你的主机要装Rewrite组件,现在国内很多WINDOWS主机都有装这个了,如果没有可以联系主机空间商。然后在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>
<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>
代码如下:</div>
<div id="phpcode2" 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>
#解决中文tag无法访问的问题<br>
RewriteRule /tag/[^/]+)/([^/]+)/?(+)?/ /index.php?tag=$1&amp;paged=$3 <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 /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";'>
但是修改之后中文tag又不能访问了,别担心,接着看下一步。<br>
修改wp-include中的classes-wp.php,之前版本可能是classes.php。</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>
代码如下:</div>
<div id="phpcode3" 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>
$pathinfo = $_SERVER['PATH_INFO'];<br>
替换为:<br>
$pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], "UTF-8", "GBK");<br>
原代码:<br>
$req_uri = $_SERVER['REQUEST_URI'];<br>
替换为:<br>
$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], "UTF-8", "GBK");</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";'>
修改后,保存下,然后将保存后的文件上传并覆盖原文件即可,这里需要注意文件保存格式。<br>
然后在固定链接中设置为自己想要的就可以了。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
附:常用WordPress固定链接格式</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
1)/%postname%/<br>
2)/%year%/%monthnum%/%postname%/<br>
3)/post/%post_id%.html<br>
4)/%year%/%monthnum%/%day%/%postname%/<br>
5)/%year%/%monthnum%/%day%/%postname%.html</p>
頁: [1]
查看完整版本: WordPress在IIS服务器上的伪静态设置方法(解决中文URL无法访问问题)