<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>戴亮 &#187; rewrite</title>
	<atom:link href="http://www.dailiang.com/tag/rewrite/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dailiang.com</link>
	<description>尘归尘,土归土!勇敢做第一个自己,自尊自爱!人生如戏,成王败寇!</description>
	<lastBuildDate>Mon, 19 Jul 2010 00:18:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Wordpress在Windows IIS主机上如何实现rewrite</title>
		<link>http://www.dailiang.com/2008/10/wordpress-in-windows-iis-host-how-to-rewrite.html</link>
		<comments>http://www.dailiang.com/2008/10/wordpress-in-windows-iis-host-how-to-rewrite.html#comments</comments>
		<pubDate>Mon, 13 Oct 2008 09:37:11 +0000</pubDate>
		<dc:creator>戴亮</dc:creator>
				<category><![CDATA[分享资源]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.dailiang.com/?p=185</guid>
		<description><![CDATA[<p>这篇文章转自<a href="http://www.phplamp.org/2008/06/wp-iis-isapi/">phplamp</a>,作为国内的大部分主机提供商都是用的windows主机,号称全能主机。但在WP的rewrite URL方面却一致是个弱项，不过看了下面的文章，你可是有福音了！</p>
<p>要说Wordpress中的完美工作环境，当然要属于Lamp平台，或是稍微逊色一点的Wamp平台;但是由于某此特殊原因，我们没有选择它们，而是选择了Windows+iis+MySql+Php，我把它统称为：Wimp平台。</p>
<p>这次我要说的就是如何在Wimp平台中实现Wordpress的完美URL结构！</p>
<p>例：<span style="color: #0000ff;">http://www.phplamp.org/2008/06/wp-iis-isapi/</span></p>
<p>用过Wordpress的应该都知道，实现这样的URL只需要在后台中：Settings-&#62;permalinks，然后设置成自己中意的 URL就行了。但是前提是您的空间支持 rewrite &#124;&#124; 您的虚拟主机支持 .htaccess。Lamp,Wamp中只要开启加载mod_rewrite模块就行了。但是Wimp却不是这么简单的，它如果想实现rewrite功 能只能借助于第三方的ISAPI组件。</p>
<p>如现在比较火的：<a href="http://www.helicontech.com/isapi_rewrite/" target="_blank">http://www.helicontech.com/isapi_rewrite/</a> 这是一个国外的组织专门为IIS写的ISAPI Rewrite组件，非常类似于Apache的mod_rewrite。有免费版与收费版！很多网友说实现WP在IIS中的rewrite功能只需要下载 一个它的组件就OK了。我在本地测试了好一阵子，没有成功，而且用它的比较麻烦，还要自己写rewrite规则！(没有成功可能是我没写正确规则， 汗！)。最后我放弃了它……</p>
<p>下面说一下本博客中(phplamp.org)用到的ISAPI组件吧：<span id="more-185"></span></p>
<p><span style="color: #ff0000;">wp-url-rewriting.dll</span> 下载地址：<a href="http://code.google.com/p/wp-url-rewriting-on-iis/downloads/list" target="_blank">http://code.google.com/p/wp-url-rewriting-on-iis/downloads/list</a></p>
<p>这是位好心的牛人专门为工作于iiS中的WP写的ISAPI rewrite组件，用它您根本就不用写rewrite规则，您只需要将其加载到您的ISAPI中，然后进wp后台定义自己的permalinks即 可。 假如你用的是虚拟主机的话，您可以联系您的空间商让其为您添加上这个组件。从此您的WP也可以完美rewrite了。</p>
<p><span style="color: #ff0000;"><strong>注意</strong>：</span>本文还没有完呢！</p>
<p>当我们定义好permalinks后，可能您会发现，我们点击中文标量的文章链接时说找不到网址。</p>
<p>例：http://www.phplamp.org/2008/06/<span style="color: #ff0000;">php%e4%b8%ad%e7%9a%84%e6%96%87%e7%ab%a0</span>/</p>
<p>这是因为：WP的编码为utf-8，而这篇文章的URL中Slug(上链接红色部分)编码为gbk。然后WP取得文章Slug后，通过它来查找文章就会找不到！因为编码不同呀。</p>
<p><span style="color: #0000ff;">更改方法：<br />
</span></p>
<p>wp-include/classes.php中(44-50行)</p>
<div class="wp_syntax">
<div class="code">
<pre class="php php" style="font-family: monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span> <span style="color: #990000;">isset</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'PATH_INFO'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span> <span style="color: #009900;">)</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'PATH_INFO'</span><span style="color: #009900;">]</span>;
<span style="color: #b1b100;">else</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> ”;
<span style="color: #000088;">$pathinfo_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">(</span>‘?’<span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo</span><span style="color: #009900;">)</span>;
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">(</span>“<span style="color: #339933;">%</span>”<span style="color: #339933;">,</span> “<span style="color: #339933;">%</span><span style="color: #800080;">25</span>″<span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo_array</span><span style="color: #009900;">[</span><span style="color: #800080;">0</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span>;
<span style="color: #000088;">$req_uri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'REQUEST_URI'</span><span style="color: #009900;">]</span>;</pre>
</div>
</div>
<p>替换为下(转换$_SERVER['PATH_INFO']和$_SERVER['REQUEST_URI']的编码)：</p>
<div class="wp_syntax">
<div class="code">
<pre class="php php" style="font-family: monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span> <span style="color: #990000;">isset</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'PATH_INFO'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span> <span style="color: #009900;">)</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'PATH_INFO'</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span> ‘utf<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span>′<span style="color: #339933;">,</span> ‘GBK’<span style="color: #009900;">)</span>;
<span style="color: #b1b100;">else</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> ”;
<span style="color: #000088;">$pathinfo_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">(</span>‘?’<span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo</span><span style="color: #009900;">)</span>;
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">(</span>“<span style="color: #339933;">%</span>”<span style="color: #339933;">,</span> “<span style="color: #339933;">%</span><span style="color: #800080;">25</span>″<span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo_array</span><span style="color: #009900;">[</span><span style="color: #800080;">0</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span>;
<span style="color: #000088;">$req_uri</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'REQUEST_URI'</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span> ‘utf<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span>′<span style="color: #339933;">,</span> ‘GBK’<span style="color: #009900;">)</span>;</pre>
</div>
</div>
<p><span>这个操作的意思就是：将Slug的编码由GBK转换为utf-8(您也可以用iconv，或是其它的函数来代替mb_convert_encoding)。</span></p>
<p>    </p>
]]></description>
			<content:encoded><![CDATA[<p>这篇文章转自<a href="http://www.phplamp.org/2008/06/wp-iis-isapi/">phplamp</a>,作为国内的大部分主机提供商都是用的windows主机,号称全能主机。但在WP的rewrite URL方面却一致是个弱项，不过看了下面的文章，你可是有福音了！</p>
<p>要说Wordpress中的完美工作环境，当然要属于Lamp平台，或是稍微逊色一点的Wamp平台;但是由于某此特殊原因，我们没有选择它们，而是选择了Windows+iis+MySql+Php，我把它统称为：Wimp平台。</p>
<p>这次我要说的就是如何在Wimp平台中实现Wordpress的完美URL结构！</p>
<p>例：<span style="color: #0000ff;">http://www.phplamp.org/2008/06/wp-iis-isapi/</span></p>
<p>用过Wordpress的应该都知道，实现这样的URL只需要在后台中：Settings-&gt;permalinks，然后设置成自己中意的 URL就行了。但是前提是您的空间支持 rewrite || 您的虚拟主机支持 .htaccess。Lamp,Wamp中只要开启加载mod_rewrite模块就行了。但是Wimp却不是这么简单的，它如果想实现rewrite功 能只能借助于第三方的ISAPI组件。</p>
<p>如现在比较火的：<a href="http://www.helicontech.com/isapi_rewrite/" target="_blank">http://www.helicontech.com/isapi_rewrite/</a> 这是一个国外的组织专门为IIS写的ISAPI Rewrite组件，非常类似于Apache的mod_rewrite。有免费版与收费版！很多网友说实现WP在IIS中的rewrite功能只需要下载 一个它的组件就OK了。我在本地测试了好一阵子，没有成功，而且用它的比较麻烦，还要自己写rewrite规则！(没有成功可能是我没写正确规则， 汗！)。最后我放弃了它……</p>
<p>下面说一下本博客中(phplamp.org)用到的ISAPI组件吧：<span id="more-185"></span></p>
<p><span style="color: #ff0000;">wp-url-rewriting.dll</span> 下载地址：<a href="http://code.google.com/p/wp-url-rewriting-on-iis/downloads/list" target="_blank">http://code.google.com/p/wp-url-rewriting-on-iis/downloads/list</a></p>
<p>这是位好心的牛人专门为工作于iiS中的WP写的ISAPI rewrite组件，用它您根本就不用写rewrite规则，您只需要将其加载到您的ISAPI中，然后进wp后台定义自己的permalinks即 可。 假如你用的是虚拟主机的话，您可以联系您的空间商让其为您添加上这个组件。从此您的WP也可以完美rewrite了。</p>
<p><span style="color: #ff0000;"><strong>注意</strong>：</span>本文还没有完呢！</p>
<p>当我们定义好permalinks后，可能您会发现，我们点击中文标量的文章链接时说找不到网址。</p>
<p>例：http://www.phplamp.org/2008/06/<span style="color: #ff0000;">php%e4%b8%ad%e7%9a%84%e6%96%87%e7%ab%a0</span>/</p>
<p>这是因为：WP的编码为utf-8，而这篇文章的URL中Slug(上链接红色部分)编码为gbk。然后WP取得文章Slug后，通过它来查找文章就会找不到！因为编码不同呀。</p>
<p><span style="color: #0000ff;">更改方法：<br />
</span></p>
<p>wp-include/classes.php中(44-50行)</p>
<div class="wp_syntax">
<div class="code">
<pre class="php php" style="font-family: monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span> <span style="color: #990000;">isset</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'PATH_INFO'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span> <span style="color: #009900;">)</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'PATH_INFO'</span><span style="color: #009900;">]</span>;
<span style="color: #b1b100;">else</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> ”;
<span style="color: #000088;">$pathinfo_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">(</span>‘?’<span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo</span><span style="color: #009900;">)</span>;
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">(</span>“<span style="color: #339933;">%</span>”<span style="color: #339933;">,</span> “<span style="color: #339933;">%</span><span style="color: #800080;">25</span>″<span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo_array</span><span style="color: #009900;">[</span><span style="color: #800080;">0</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span>;
<span style="color: #000088;">$req_uri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'REQUEST_URI'</span><span style="color: #009900;">]</span>;</pre>
</div>
</div>
<p>替换为下(转换$_SERVER['PATH_INFO']和$_SERVER['REQUEST_URI']的编码)：</p>
<div class="wp_syntax">
<div class="code">
<pre class="php php" style="font-family: monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span> <span style="color: #990000;">isset</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'PATH_INFO'</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span> <span style="color: #009900;">)</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'PATH_INFO'</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span> ‘utf<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span>′<span style="color: #339933;">,</span> ‘GBK’<span style="color: #009900;">)</span>;
<span style="color: #b1b100;">else</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> ”;
<span style="color: #000088;">$pathinfo_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">(</span>‘?’<span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo</span><span style="color: #009900;">)</span>;
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">(</span>“<span style="color: #339933;">%</span>”<span style="color: #339933;">,</span> “<span style="color: #339933;">%</span><span style="color: #800080;">25</span>″<span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo_array</span><span style="color: #009900;">[</span><span style="color: #800080;">0</span><span style="color: #009900;">]</span><span style="color: #009900;">)</span>;
<span style="color: #000088;">$req_uri</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">(</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">[</span><span>'REQUEST_URI'</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span> ‘utf<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span>′<span style="color: #339933;">,</span> ‘GBK’<span style="color: #009900;">)</span>;</pre>
</div>
</div>
<p><span>这个操作的意思就是：将Slug的编码由GBK转换为utf-8(您也可以用iconv，或是其它的函数来代替mb_convert_encoding)。</span></p>
<p><!-- /Header --> <!-- Container --> <!-- single post content --> <!-- single post loop --> <!-- title of the single pot --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailiang.com/2008/10/wordpress-in-windows-iis-host-how-to-rewrite.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
