<?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; 伪静态</title>
	<atom:link href="http://www.onono.org/tag/%e4%bc%aa%e9%9d%99%e6%80%81/feed" rel="self" type="application/rss+xml" />
	<link>http://www.onono.org</link>
	<description>一树的随想、生活与资料存档。</description>
	<lastBuildDate>Sun, 18 Sep 2011 01:38:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>浅谈各个系统下的伪静态</title>
		<link>http://www.onono.org/2010/10/539.htm</link>
		<comments>http://www.onono.org/2010/10/539.htm#comments</comments>
		<pubDate>Tue, 26 Oct 2010 10:48:06 +0000</pubDate>
		<dc:creator>一树</dc:creator>
				<category><![CDATA[技术文档]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[伪静态]]></category>
		<category><![CDATA[重写]]></category>

		<guid isPermaLink="false">http://www.onono.org/?p=539</guid>
		<description><![CDATA[目前各大流行的web服务器上都可以设置伪静态（URL重写），下面简单说明一下。 一、IIS 1、ISAPI（win2003） IIS上比较通用的一种伪静态方法，通过加载ISAPI扩展，来实现伪静态。 通常会载入一个dll文件和一个包含伪静态规则的httpd.ini文件。 2、应用程序映射 ASP.Net程序通常会采用的一种方法，一个URL请求发送到服务器以后，服务器会识别请求文件的扩展名，一些特定的后缀名的文件会交给特定的应用程序来处理，伪静态请求的文件肯定是服务器上不存在的一个文件，利用这个特性，在web.config文件中做好规则设置，然后设置应用程序映射就可以达到伪静态的目的。 3、URL Rewrite Module（IIS7） 在IIS7，伪静态已经升级为一个模块，可以直接写入规则。 二、Apache Apache通过在服务器上加载mod_rewrite组件，自动检测目录下的.htaccess文件来实现伪静态。 当然，伪静态规则不一定要写在.htaccess文件里，避免使用.htaccess可以提高服务器效率（AllowOverride None），如果有足够的服务器权限，将伪静态规则直接写入虚拟主机配置文件中是最好的。 三、Nginx Nginx和Apache差不多，也是在配置文件中写入伪静态规则。 Discuz!在Nginx下的伪静态规则（部分演示） rewrite ^/archiver/((fid&#124;tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last; rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&#38;page=$2 last; rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&#38;extra=page%3D$3&#38;page=$2 last; rewrite ^/space-(username&#124;uid)-(.+)\.html$ /space.php?$1=$2 last; rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last; break; Nginx重写语法，官方文档：http://wiki.nginx.org/HttpRewriteModule &#8230; <a href="http://www.onono.org/2010/10/539.htm">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>目前各大流行的web服务器上都可以设置伪静态（URL重写），下面简单说明一下。</p>
<p>一、IIS</p>
<p style="padding-left: 30px;">1、ISAPI（win2003）</p>
<p style="padding-left: 30px;">IIS上比较通用的一种伪静态方法，通过加载ISAPI扩展，来实现伪静态。</p>
<p style="padding-left: 30px;"><a href="http://www.onono.org/wp-content/uploads/2010/10/isapi.png" class="highslide-image" onclick="return hs.expand(this);"><img class="alignnone size-medium wp-image-540" title="isapi" src="http://www.onono.org/wp-content/uploads/2010/10/isapi-300x294.png" alt="" width="300" height="294" /></a><span id="more-539"></span></p>
<p style="padding-left: 30px;">通常会载入一个dll文件和一个包含伪静态规则的httpd.ini文件。</p>
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">2、应用程序映射</p>
<p style="padding-left: 30px;"><a href="http://www.onono.org/wp-content/uploads/2010/10/aspnet2.jpg" class="highslide-image" onclick="return hs.expand(this);"><img class="alignnone size-medium wp-image-541" title="应用程序映射" src="http://www.onono.org/wp-content/uploads/2010/10/aspnet2-270x300.jpg" alt="" width="270" height="300" /></a></p>
<p style="padding-left: 30px;">ASP.Net程序通常会采用的一种方法，一个URL请求发送到服务器以后，服务器会识别请求文件的扩展名，一些特定的后缀名的文件会交给特定的应用程序来处理，伪静态请求的文件肯定是服务器上不存在的一个文件，利用这个特性，在web.config文件中做好规则设置，然后设置应用程序映射就可以达到伪静态的目的。</p>
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">3、URL Rewrite Module（IIS7）</p>
<p style="padding-left: 30px;"><a href="http://www.onono.org/wp-content/uploads/2010/10/iis7.png" class="highslide-image" onclick="return hs.expand(this);"><img class="alignnone size-medium wp-image-546" title="iis7" src="http://www.onono.org/wp-content/uploads/2010/10/iis7-300x215.png" alt="" width="300" height="215" /></a></p>
<p style="padding-left: 30px;">在IIS7，伪静态已经升级为一个模块，可以直接写入规则。</p>
<p>二、Apache</p>
<p style="padding-left: 30px;"><a href="http://www.onono.org/wp-content/uploads/2010/10/htaccess.jpg" class="highslide-image" onclick="return hs.expand(this);"><img class="alignnone size-medium wp-image-547" title="htaccess" src="http://www.onono.org/wp-content/uploads/2010/10/htaccess-300x175.jpg" alt="" width="300" height="175" /></a></p>
<p style="padding-left: 30px;">Apache通过在服务器上加载mod_rewrite组件，自动检测目录下的.htaccess文件来实现伪静态。</p>
<p style="padding-left: 30px;">当然，伪静态规则不一定要写在.htaccess文件里，避免使用.htaccess可以提高服务器效率（AllowOverride None），如果有足够的服务器权限，将伪静态规则直接写入虚拟主机配置文件中是最好的。</p>
<p>三、Nginx</p>
<p style="padding-left: 30px;">Nginx和Apache差不多，也是在配置文件中写入伪静态规则。</p>
<p style="padding-left: 30px;"><a href="http://www.onono.org/wp-content/uploads/2010/10/nginx.jpg" class="highslide-image" onclick="return hs.expand(this);"><img class="alignnone size-medium wp-image-549" title="nginx" src="http://www.onono.org/wp-content/uploads/2010/10/nginx-300x201.jpg" alt="" width="300" height="201" /></a></p>
<p style="padding-left: 30px;">Discuz!在Nginx下的伪静态规则（部分演示）</p>
<pre class="1" style="padding-left: 30px;">rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&amp;page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&amp;extra=page%3D$3&amp;page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
break;</pre>
<p style="padding-left: 30px;">Nginx重写语法，官方文档：<a title="nginx" href="http://wiki.nginx.org/HttpRewriteModule" target="_blank">http://wiki.nginx.org/HttpRewriteModule</a></p>
<p style="padding-left: 30px;">
<p>四、lighttpd（使用较少，略）</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onono.org/2010/10/539.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>伪静态，很好很强大</title>
		<link>http://www.onono.org/2009/07/206.htm</link>
		<comments>http://www.onono.org/2009/07/206.htm#comments</comments>
		<pubDate>Sun, 12 Jul 2009 08:28:14 +0000</pubDate>
		<dc:creator>一树</dc:creator>
				<category><![CDATA[技术文档]]></category>
		<category><![CDATA[rewriter]]></category>
		<category><![CDATA[伪静态]]></category>

		<guid isPermaLink="false">http://www.onono.org/?p=206</guid>
		<description><![CDATA[自从使用了linux主机，不管是CentOS、FreeBSD还是Ubuntu，腰不酸了，腿不痛了，PR也直线上升了~ 好了，废话少说，用WordPress肯定会选linux主机而不会选windows主机，为什么？除了性能等因素，我看重的，是伪静态。WordPress默认会在目录下设置一个.htaccess文件，在里面写入伪静态规则（重写规则,rewrite-rules）。下面来看看这个文件里写了什么东西： # BEGIN WordPress &#160; RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &#160; # END WordPress RewriteEngine、RewriteBase、RewriteCond、RewriteRule等指令可以在Apache文档里查阅：http://lamp.linux.gov.cn/Apache/ApacheMenu/rewrite/rewrite_guide.html WordPress的这几句简单的重写规则，把所有的操作都交由index.php处理。 比如，打开一树相册的地址为http://www.onono.org/album/，看上去是访问了一个目录，实际上是把album作为参数，传递给index.php，然后回显正确的页面（Page），相当于访问http://www.onono.org/index.php?p=103。 WordPress的重写过程虽然简单，但是内部的处理过程不简单，要同时处理页面、分类、文章正文等URL被重写后的请求。 如果WordPress的这个例子看不大明白，换一个简单的，来自Discuz的一条重写规则： RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&#38;amp;page=$2 在访问某板块的帖子列表页，打开的页面是forum-23-1.html，实际上打开的页面为forumdisplay.php?fid=23&#38;page=1，显示id为23的板块第1页帖子。 这样有什么好处呢？简单的说，可以让很长的URL变得很短、好看、易记。 搜索引擎在抓取页面的时候，计算页面权重，http://www.onono.org/album/肯定比http://www.onono.org/index.php?p=103的权重高，一些静态html页面（就像forum-23-1.html一样）比带参数的forumdisplay.php?fid=23&#38;page=1更受搜索引擎欢迎。]]></description>
			<content:encoded><![CDATA[<p>自从使用了linux主机，不管是CentOS、FreeBSD还是Ubuntu，腰不酸了，腿不痛了，PR也直线上升了~</p>
<p>好了，废话少说，用WordPress肯定会选linux主机而不会选windows主机，为什么？除了性能等因素，我看重的，是伪静态。WordPress默认会在目录下设置一个.htaccess文件，在里面写入伪静态规则（重写规则,rewrite-rules）。下面来看看这个文件里写了什么东西：<br />
<span id="more-206"></span></p>
<div class="geshi html">
<ol>
<li class="li1">
<div class="de1"># BEGIN WordPress
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">RewriteEngine On
</div>
</li>
<li class="li1">
<div class="de1">RewriteBase /
</div>
</li>
<li class="li1">
<div class="de1">RewriteCond %{REQUEST_FILENAME} !-f
</div>
</li>
<li class="li1">
<div class="de1">RewriteCond %{REQUEST_FILENAME} !-d
</div>
</li>
<li class="li1">
<div class="de1">RewriteRule . /index.php [L]
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"># END WordPress</div>
</li>
</ol>
</div>
<p>RewriteEngine、RewriteBase、RewriteCond、RewriteRule等指令可以在Apache文档里查阅：<a href="http://lamp.linux.gov.cn/Apache/ApacheMenu/rewrite/rewrite_guide.html" target="_blank">http://lamp.linux.gov.cn/Apache/ApacheMenu/rewrite/rewrite_guide.html</a></p>
<p>WordPress的这几句简单的重写规则，把所有的操作都交由index.php处理。<br />
比如，打开一树相册的地址为<a href="http://www.onono.org/album/">http://www.onono.org/album/</a>，看上去是访问了一个目录，实际上是把album作为参数，传递给index.php，然后回显正确的页面（Page），相当于访问<a href="http://www.onono.org/index.php?p=103">http://www.onono.org/index.php?p=103</a>。<br />
WordPress的重写过程虽然简单，但是内部的处理过程不简单，要同时处理页面、分类、文章正文等URL被重写后的请求。</p>
<p>如果WordPress的这个例子看不大明白，换一个简单的，来自Discuz的一条重写规则：</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&amp;amp;page=$2</div>
</li>
</ol>
</div>
<p>在访问某板块的帖子列表页，打开的页面是forum-23-1.html，实际上打开的页面为forumdisplay.php?fid=23&amp;page=1，显示id为23的板块第1页帖子。</p>
<p>这样有什么好处呢？简单的说，可以让很长的URL变得很短、好看、易记。<br />
搜索引擎在抓取页面的时候，计算页面权重，<a href="http://www.onono.org/album/">http://www.onono.org/album/</a>肯定比<a href="http://www.onono.org/index.php?p=103">http://www.onono.org/index.php?p=103</a>的权重高，一些静态html页面（就像forum-23-1.html一样）比带参数的forumdisplay.php?fid=23&amp;page=1更受搜索引擎欢迎。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onono.org/2009/07/206.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

