在 IIS 下使用 WordPress ,最闹心的事莫过于对 WordPress静态化设置。网上有很多基于 ISAPI_Rewrite 的 URL 重写规则,大部分都不是太好用,这里推荐两款适用于IIS伪静态环境下的 WP URL 重写组件,供有独立主机的朋友轻松配置 WordPress 伪静态。
下面说一下WordPress静态化用到的ISAPI组件吧:
wp-url-rewriting.dll 下载地址:http://code.google.com/p/wp-url-rewriting-on-iis/downloads/list
这是位好心的牛人专门为工作于IIS伪静态中的WP写的ISAPI rewrite组件,用它您根本就不用写rewrite规则,您只需要将其加载到您的ISAPI中,然后进wp后台定义自己的permalinks即可。 假如你用的是虚拟主机的话,您可以联系您的空间商让其为您添加上这个组件。从此您的WordPress静态化了。
WordPress静态化存在的问题:
无法重写以.html结尾的URL,只能以目录形式组成,这个问题我已经在官方论坛提出,希望作者能尽快解决这个问题。
注意:本文还没有完呢![/b]
当我们定义好permalinks后,可能您会发现,我们点击中文标量的文章链接时说找不到网址。
例:http://www.xxx.com/2008/06/php%e4%b8%ad%e7%9a%84%e6%96%87%e7%ab%a0/
这是因为:WP的编码为utf-8,而这篇文章的URL中Slug(上链接红色部分)编码为gbk。然后WP取得文章Slug后,通过它来查找文章就会找不到!因为编码不同呀。
更改WordPress静态化方法有两种:
第1种:
IIS伪静态多加载一个,因为之前那个是特别制作的,所以没有冲突。ISAPI_Rewrite
- [ISAPI_Rewrite]
- # 3600 = 1 hour
- CacheClockRate 3600
- RepeatLimit 32
- RewriteRule /tag/(.*)/ /index\.php\?tag=$1
复制代码
第2种:
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”);
复制代码
IIS伪静态这个操作的意思就是:将Slug的编码由GBK转换为utf-8(您也可以用iconv,或是其它的函数来代替mb_convert_encoding)。
这样就能支持任意字符的 tags 了,完美解决 WordPress静态化重写问题。
注意 / 问题,规则正则结尾带 / ,设置固定链接时使用 /%postname%/ ,最后面要加 / 。
除此之外,用过 Discuz! 论坛的朋友都知道 Discuz!提供有 Rewrite 组件,IIS伪静态配置方法和效果与 ISAPI_Rewrite 相同。
# # 自定义链接 /html/%post_id%.html
[ISAPI_Rewrite]
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# # 形式:/html/PostID.html
# # 自定义链接 /html/%post_id%.html
RewriteRule /html/tag/(.*) /index\.php\?tag=$1
RewriteRule /tag/(.*) /index\.php\?tag=$1
RewriteRule /(about|contact|about-copyright|favor|archives|tags|sitemap|taotao) /index\.php\?pagename=$1
RewriteRule /html/category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed\.php\?category_name=$1&feed=$2
RewriteRule /html/category/?(.*) /index\.php\?category_name=$1
RewriteRule /author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed\.php\?author_name=$1&feed=$2
RewriteRule /author/?(.*) /index\.php\?author_name=$1
RewriteRule /rss.xml /wp-feed\.php/\?feed=rss2
RewriteRule /feed/?$ /wp-feed\.php/\?feed=rss2
RewriteRule /comments/feed/?$ /wp-feed\.php/\?feed=comments-rss2
# RewriteRule /([0-9]+)/?([0-9]+)?/?$ /index\.php\?p=$1&page=$2
# RewriteRule /html/([0-9]+)/?([0-9]+)?/?$ /index\.php\?p=$1&page=$2
RewriteRule /html/([0-9]+).html /index\.php\?p=$1 [I]
RewriteRule /page/(.*)/?s=(.*) /index\.php\?s=$2&paged=$1
RewriteRule /page/(.*) /index\.php\?paged=$1
RewriteRule /html/date/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/([^/]+)/?([0-9]+)?/?$ /index\.php\?year=$1&monthnum=$2&day=$3&name=$4&page=$5
RewriteRule /html/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index\.php\?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /html/date/([0-9]{4})/([0-9]{1,2})/?$ /index\.php\?year=$1&monthnum=$2&page=$3
RewriteRule /html/([0-9]+).html/(feed|rdf|rss|rss2|atom) /index\.php\?feed=rss2&p=$1
RewriteRule /html/([0-9]+).html/trackback /wp-trackback\.php\?p=$1











有点看不明白啊
我也是,看着好头大
感觉有点问题,每次我留言后都显示“无法找到该页” 不过留言还是成功了的
我这个留言后提交显示的这个页面还没静态化成功,而且分类分页也还不行,还在研究中
尊敬的博主你好,我使用的godaddy的免费windows主机(iis7),同样,在后台设置了静态化链接,形式是/目录/文章名.html,根据WordPress后台的提示在网站根目录修改了web.config文件,伪静态是没有问题文章和分类都可以正常访问,但是所有的tag都是无法访问,请问如何在web.config中添加相关的内容呢?