<?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.crazylemon.net/tag/rewrite/feed" rel="self" type="application/rss+xml" />
	<link>http://www.crazylemon.net</link>
	<description>上帝无用，天使无用</description>
	<lastBuildDate>Fri, 03 Sep 2010 19:25:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>zen-cart rewrite 地址产品名字挤在一起的解决</title>
		<link>http://www.crazylemon.net/zencart/3307.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=zen-cart-rewrite-%25e5%259c%25b0%25e5%259d%2580%25e4%25ba%25a7%25e5%2593%2581%25e5%25ae%25a2%25e5%25ad%2597%25e6%258c%25a4%25e5%259c%25a8%25e4%25b8%2580%25e8%25b5%25b7%25e7%259a%2584%25e8%25a7%25a3%25e5%2586%25b3</link>
		<comments>http://www.crazylemon.net/zencart/3307.html#comments</comments>
		<pubDate>Sat, 31 Jul 2010 02:15:38 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[ZenCart]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=3307</guid>
		<description><![CDATA[发现有个网站，装了ultimate_seo_urls后，不知道什么原因，生成的产品或目录链接地址中，产品名字挤在了一块，就是没有分隔符 而通常来说，装完ultimate_seo_urls后，生成的链接，应该是产品名字如果包括多个单词的话，单词与单词之前是用&#8221;-&#8221;号连接的 原因是有人在后台seo urls里面设置了这一项为ture: Remove all non-alphanumeric characters? 这个功能，是将除字数和字母外的其它字符去掉，解决方法： Remove all non-alphanumeric characters? 改为flase，并Reset SEO URLs Cache 相关日志06/03/2009 -- url rewrite是什么 (0)05/31/2009 -- 十大WordPress的SEO优化技巧 (0)07/16/2010 -- Google算法调整,大批链接工厂被端(转自DDM) (1)04/05/2010 -- 如何写robots.txt？(摘点石) (1)11/14/2009 -- 什么是PR劫持 (0)]]></description>
			<content:encoded><![CDATA[<p>发现有个网站，装了ultimate_seo_urls后，不知道什么原因，生成的产品或目录链接地址中，产品名字挤在了一块，就是没有分隔符</p>
<p>而通常来说，装完ultimate_seo_urls后，生成的链接，应该是产品名字如果包括多个单词的话，单词与单词之前是用&#8221;-&#8221;号连接的</p>
<p>原因是有人在后台seo urls里面设置了这一项为ture:</p>
<p><strong>Remove all non-alphanumeric characters?</strong></p>
<p>这个功能，是将除字数和字母外的其它字符去掉，解决方法：</p>
<p><strong>Remove all non-alphanumeric characters? </strong>改为flase，并Reset SEO URLs Cache</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/03/2009 -- <a href="http://www.crazylemon.net/php/413.html" title="url rewrite是什么">url rewrite是什么</a> (0)</li><li>05/31/2009 -- <a href="http://www.crazylemon.net/seo/267.html" title="十大WordPress的SEO优化技巧">十大WordPress的SEO优化技巧</a> (0)</li><li>07/16/2010 -- <a href="http://www.crazylemon.net/seo/3271.html" title="Google算法调整,大批链接工厂被端(转自DDM)">Google算法调整,大批链接工厂被端(转自DDM)</a> (1)</li><li>04/05/2010 -- <a href="http://www.crazylemon.net/seo/3025.html" title="如何写robots.txt？(摘点石)">如何写robots.txt？(摘点石)</a> (1)</li><li>11/14/2009 -- <a href="http://www.crazylemon.net/seo/2464.html" title="什么是PR劫持">什么是PR劫持</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/zencart/3307.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>使用.htaccess将网站首页301重定向到子页面</title>
		<link>http://www.crazylemon.net/apache/2816.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=%25e4%25bd%25bf%25e7%2594%25a8-htaccess%25e5%25b0%2586%25e7%25bd%2591%25e7%25ab%2599%25e9%25a6%2596%25e9%25a1%25b5301%25e9%2587%258d%25e5%25ae%259a%25e5%2590%2591%25e5%2588%25b0%25e5%25ad%2590%25e9%25a1%25b5%25e9%259d%25a2</link>
		<comments>http://www.crazylemon.net/apache/2816.html#comments</comments>
		<pubDate>Wed, 20 Jan 2010 10:50:59 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=2816</guid>
		<description><![CDATA[因为有个网站的首页被Google K掉了，具体体现为site:yourdomain.com时，搜索结果底部有如下提示： 根据我们收到的依据 US Digital Millennium Copyright Act（美国数字千年版权法案）提出的投诉，我们已从此网页上删除了 1 个结果。如果需要，您可以在 ChillingEffects.org 上阅读导致删除搜索结果的 DMCA 投诉。 同事提议弄个子页面和首页类似，然后将首页重定向到这个子页面试试，我真不懂这样有什么好处 具体做法是，在.htaccess里添加这么条规则： RewriteRule ^$ http://www.yourdomain.com/yourpage.html [L,R=301] 相关日志11/07/2009 -- Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式 (6)11/05/2009 -- 网站遭遇攻击 (0)09/11/2009 -- 301重定向进行URL标准化设置 (1)06/06/2009 -- Nginx的WordPress配置 (0)05/12/2010 -- 比较全的域名whois服务器地址 (0)]]></description>
			<content:encoded><![CDATA[<p>因为有个网站的首页被Google K掉了，具体体现为site:yourdomain.com时，搜索结果底部有如下提示：</p>
<p id="mfr"><em>根据我们收到的依据 US Digital Millennium Copyright Act（美国数字千年版权法案）提出的投诉，我们已从此网页上删除了 1 个结果。如果需要，您可以在 ChillingEffects.org 上阅读导致删除搜索结果的 DMCA 投诉。</em></p>
<p>同事提议弄个子页面和首页类似，然后将首页重定向到这个子页面试试，我真不懂这样有什么好处</p>
<p>具体做法是，在.htaccess里添加这么条规则：</p>
<p>RewriteRule ^$ http://www.yourdomain.com/yourpage.html [L,R=301]</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>11/07/2009 -- <a href="http://www.crazylemon.net/apache/2400.html" title="Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式">Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式</a> (6)</li><li>11/05/2009 -- <a href="http://www.crazylemon.net/web/2372.html" title="网站遭遇攻击">网站遭遇攻击</a> (0)</li><li>09/11/2009 -- <a href="http://www.crazylemon.net/seo/1812.html" title="301重定向进行URL标准化设置">301重定向进行URL标准化设置</a> (1)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>05/12/2010 -- <a href="http://www.crazylemon.net/work/3145.html" title="比较全的域名whois服务器地址">比较全的域名whois服务器地址</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/apache/2816.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式</title>
		<link>http://www.crazylemon.net/apache/2400.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=apache-mod_rewrite%25e6%25a8%25a1%25e5%259d%2597%25e4%25b8%25adrewritecond%25e5%2592%258crewriterule%25e7%259a%2584%25e6%258c%2587%25e4%25bb%25a4%25e6%25a0%25bc%25e5%25bc%258f</link>
		<comments>http://www.crazylemon.net/apache/2400.html#comments</comments>
		<pubDate>Sat, 07 Nov 2009 07:38:11 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[ping]]></category>
		<category><![CDATA[pr]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[rm]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vi]]></category>
		<category><![CDATA[正则表达式]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=2400</guid>
		<description><![CDATA[RewriteCond指令格式 语法: RewriteCond TestString CondPattern 1) TestString是一个纯文本的字符串，但是可以包含可扩展的成分 2) CondPattern是条件pattern, 即一个应用于当前实例TestString的正则表达式, 即TestString将会被计算然后与CondPattern匹配. 3) 另外,还可以为CondPattern追加特殊的标记[flags] 作为RewriteCond指令的第三个参数。Flags是一个以逗号分隔的以下标记的列表： &#8216;nocase&#124;NC&#8217;  它使测试忽略大小写, 即TestString和CondPattern无大小写检查 &#8216;ornext&#124;OR&#8217;  它以OR方式组合若干规则的条件，而不是隐含的AND。 RewriteRule 指令 语法: RewriteRule Pattern Substitution 1) Pattern是一个作用于当前URL的兼容perl的正则表达式. 这里的“当前&#8221;是指该规则生效时的URL的值。 2) Substitution是，当原始URL与Pattern相匹配时，用以替代(或替换)的字符串。 3) 此外，Substitution还可以追加特殊标记[flags]  作为RewriteRule指令的第三个参数。 Flags是一个包含以逗号分隔的下列标记的列表: &#8216;redirect&#124;R [=code]&#8216; (强制重定向 redirect) 以http://thishost[:thisport]/(使新的URL成为一个URI) 为前缀的Substitution可以强制性执行一个外部重定向。 如果code没有指定，则产生一个HTTP响应代码302(临时性移动)。 如果需要使用在300-400范围内的其他响应代码，只需在此指定这个数值即可， 另外，还可以使用下列符号名称之一: temp (默认的), permanent, seeother. 用它可以把规范化的URL反馈给客户端，如, 重写“/~&#8221;为 “/u/&#8221;，或对/u/user加上斜杠，等等。 注意: 在使用这个标记时，必须确保该替换字段是一个有效的URL! 否则，它会指向一个无效的位置! 并且要记住，此标记本身只是对URL加上 http://thishost[:thisport]/的前缀，重写操作仍然会继续。 [...]]]></description>
			<content:encoded><![CDATA[<p>RewriteCond指令格式<br />
语法: RewriteCond TestString CondPattern<br />
1) TestString是一个纯文本的字符串，但是可以包含可扩展的成分<br />
2) CondPattern是条件pattern, 即一个应用于当前实例TestString的正则表达式, 即TestString将会被计算然后与CondPattern匹配.<br />
3) 另外,还可以为CondPattern追加特殊的标记[flags] 作为RewriteCond指令的第三个参数。Flags是一个以逗号分隔的以下标记的列表：<br />
&#8216;nocase|NC&#8217;  它使测试忽略大小写, 即TestString和CondPattern无大小写检查<br />
&#8216;ornext|OR&#8217;  它以OR方式组合若干规则的条件，而不是隐含的AND。</p>
<p>RewriteRule 指令<br />
语法: RewriteRule Pattern Substitution<br />
1) Pattern是一个作用于当前URL的兼容perl的正则表达式. 这里的“当前&#8221;是指该规则生效时的URL的值。<br />
2) Substitution是，当原始URL与Pattern相匹配时，用以替代(或替换)的字符串。<br />
3) 此外，Substitution还可以追加特殊标记[flags]  作为RewriteRule指令的第三个参数。 Flags是一个包含以逗号分隔的下列标记的列表:<br />
&#8216;redirect|R [=code]&#8216; (强制重定向 redirect)<br />
以http://thishost[:thisport]/(使新的URL成为一个URI) 为前缀的Substitution可以强制性执行一个外部重定向。 如果code没有指定，则产生一个HTTP响应代码302(临时性移动)。 如果需要使用在300-400范围内的其他响应代码，只需在此指定这个数值即可， 另外，还可以使用下列符号名称之一: temp (默认的), permanent, seeother. 用它可以把规范化的URL反馈给客户端，如, 重写“/~&#8221;为 “/u/&#8221;，或对/u/user加上斜杠，等等。</p>
<p>注意: 在使用这个标记时，必须确保该替换字段是一个有效的URL! 否则，它会指向一个无效的位置! 并且要记住，此标记本身只是对URL加上 http://thishost[:thisport]/的前缀，重写操作仍然会继续。 通常，你会希望停止重写操作而立即重定向，则还需要使用&#8217;L'标记.</p>
<p>&#8216;forbidden|F&#8217; (强制URL为被禁止的 forbidden)<br />
强制当前URL为被禁止的，即，立即反馈一个HTTP响应代码403(被禁止的)。 使用这个标记，可以链接若干RewriteConds以有条件地阻塞某些URL。<br />
&#8216;gone|G&#8217; (强制URL为已废弃的 gone)<br />
强制当前URL为已废弃的，即，立即反馈一个HTTP响应代码410(已废弃的)。 使用这个标记，可以标明页面已经被废弃而不存在了.<br />
&#8216;proxy|P&#8217; (强制为代理 proxy)<br />
此标记使替换成分被内部地强制为代理请求，并立即(即， 重写规则处理立即中断)把处理移交给代理模块。 你必须确保此替换串是一个有效的(比如常见的以 http://hostname开头的)能够为Apache代理模块所处理的URI。 使用这个标记，可以把某些远程成分映射到本地服务器名称空间， 从而增强了ProxyPass指令的功能。<br />
注意: 要使用这个功能，代理模块必须编译在Apache服务器中。 如果你不能确定，可以检查“httpd -l&#8221;的输出中是否有mod_proxy.c。 如果有，则mod_rewrite可以使用这个功能； 如果没有，则必须启用mod_proxy并重新编译“httpd&#8221;程序。</p>
<p>&#8216;last|L&#8217; (最后一个规则 last)<br />
立即停止重写操作，并不再应用其他重写规则。 它对应于Perl中的last命令或C语言中的break命令。 这个标记可以阻止当前已被重写的URL为其后继的规则所重写。 举例，使用它可以重写根路径的URL(&#8216;/&#8217;)为实际存在的URL, 比如, &#8216;/e/www/&#8217;.<br />
&#8216;next|N&#8217; (重新执行 next round)<br />
重新执行重写操作(从第一个规则重新开始). 这时再次进行处理的URL已经不是原始的URL了，而是经最后一个重写规则处理的URL。 它对应于Perl中的next命令或C语言中的continue命令。 此标记可以重新开始重写操作，即, 立即回到循环的头部。<br />
但是要小心，不要制造死循环!<br />
&#8216;chain|C&#8217; (与下一个规则相链接 chained)<br />
此标记使当前规则与下一个(其本身又可以与其后继规则相链接的， 并可以如此反复的)规则相链接。 它产生这样一个效果: 如果一个规则被匹配，通常会继续处理其后继规则， 即，这个标记不起作用；如果规则不能被匹配， 则其后继的链接的规则会被忽略。比如，在执行一个外部重定向时， 对一个目录级规则集，你可能需要删除“.www&#8221; (此处不应该出现“.www&#8221;的)。<br />
&#8216;type|T=MIME-type&#8217; (强制MIME类型 type)<br />
强制目标文件的MIME类型为MIME-type。 比如，它可以用于模拟mod_alias中的ScriptAlias指令， 以内部地强制被映射目录中的所有文件的MIME类型为“application/x-httpd-cgi&#8221;.<br />
&#8216;nosubreq|NS&#8217; (仅用于不对内部子请求进行处理 no internal sub-request)<br />
在当前请求是一个内部子请求时，此标记强制重写引擎跳过该重写规则。 比如，在mod_include试图搜索可能的目录默认文件(index.xxx)时， Apache会内部地产生子请求。对子请求，它不一定有用的，而且如果整个规则集都起作用， 它甚至可能会引发错误。所以，可以用这个标记来排除某些规则。</p>
<p>根据你的需要遵循以下原则: 如果你使用了有CGI脚本的URL前缀，以强制它们由CGI脚本处理， 而对子请求处理的出错率(或者开销)很高，在这种情况下，可以使用这个标记。</p>
<p>&#8216;nocase|NC&#8217; (忽略大小写 no case)<br />
它使Pattern忽略大小写，即, 在Pattern与当前URL匹配时，&#8217;A-Z&#8217; 和&#8217;a-z&#8217;没有区别。<br />
&#8216;qsappend|QSA&#8217; (追加请求串 query string append)<br />
此标记强制重写引擎在已有的替换串中追加一个请求串，而不是简单的替换。 如果需要通过重写规则在请求串中增加信息，就可以使用这个标记。<br />
&#8216;noescape|NE&#8217; (在输出中不对URI作转义 no URI escaping)<br />
此标记阻止mod_rewrite对重写结果应用常规的URI转义规则。 一般情况下，特殊字符(如&#8217;%', &#8216;$&#8217;, &#8216;;&#8217;等)会被转义为等值的十六进制编码。 此标记可以阻止这样的转义，以允许百分号等符号出现在输出中，如：<br />
RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]</p>
<p>可以使&#8217;/foo/zed&#8217;转向到一个安全的请求&#8217;/bar?arg=P1=zed&#8217;.<br />
&#8216;passthrough|PT&#8217; (移交给下一个处理器 pass through)<br />
此标记强制重写引擎将内部结构request_rec中的uri字段设置为 filename字段的值，它只是一个小修改，使之能对来自其他URI到文件名翻译器的 Alias，ScriptAlias, Redirect 等指令的输出进行后续处理。举一个能说明其含义的例子： 如果要通过mod_rewrite的重写引擎重写/abc为/def， 然后通过mod_alias使/def转变为/ghi，可以这样:<br />
RewriteRule ^/abc(.*) /def$1 [PT]<br />
Alias /def /ghi</p>
<p>如果省略了PT标记，虽然mod_rewrite运作正常， 即, 作为一个使用API的URI到文件名翻译器， 它可以重写uri=/abc/…为filename=/def/…， 但是，后续的mod_alias在试图作URI到文件名的翻译时，则会失效。<br />
注意: 如果需要混合使用不同的包含URI到文件名翻译器的模块时， 就必须使用这个标记。。 混合使用mod_alias和mod_rewrite就是个典型的例子。</p>
<p>For Apache hackers<br />
如果当前Apache API除了URI到文件名hook之外，还有一个文件名到文件名的hook， 就不需要这个标记了! 但是，如果没有这样一个hook，则此标记是唯一的解决方案。 Apache Group讨论过这个问题，并在Apache 2.0 版本中会增加这样一个hook。<br />
&#8216;skip|S=num&#8217; (跳过后继的规则 skip)<br />
此标记强制重写引擎跳过当前匹配规则后继的num个规则。 它可以实现一个伪if-then-else的构造: 最后一个规则是then从句，而被跳过的skip=N个规则是else从句. (它和&#8217;chain|C&#8217;标记是不同的!)<br />
&#8216;env|E=VAR:VAL&#8217; (设置环境变量 environment variable)<br />
此标记使环境变量VAR的值为VAL, VAL可以包含可扩展的反向引用的正则表达式$N和%N。 此标记可以多次使用以设置多个变量。 这些变量可以在其后许多情况下被间接引用，但通常是在XSSI (via &lt;!–#echo var=&#8221;VAR&#8221;–&gt;) or CGI (如 $ENV{&#8216;VAR&#8217;})中， 也可以在后继的RewriteCond指令的pattern中通过%{ENV:VAR}作引用。 使用它可以从URL中剥离并记住一些信息。<br />
&#8216;cookie|CO=NAME:VAL:domain[:lifetime[:path]]&#8217; (设置cookie)<br />
它在客户端浏览器上设置一个cookie。 cookie的名称是NAME，其值是VAL。 domain字段是该cookie的域，比如&#8217;.apache.org&#8217;, 可选的lifetime是cookie生命期的分钟数， 可选的path是cookie的路径。</p>
<p> 其实apache手册中有 http://man.chinaunix.net/newsoft/ApacheManual/mod/mod_rewrite.html</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>01/21/2009 -- <a href="http://www.crazylemon.net/linux/5.html" title="Linux常用命令大全 ">Linux常用命令大全 </a> (0)</li><li>06/17/2009 -- <a href="http://www.crazylemon.net/linux/678.html" title="Linux文件查找命令find,xargs详述">Linux文件查找命令find,xargs详述</a> (0)</li><li>05/30/2009 -- <a href="http://www.crazylemon.net/windows/250.html" title="IIS 错误代码大汇总">IIS 错误代码大汇总</a> (0)</li><li>02/28/2009 -- <a href="http://www.crazylemon.net/nginx/134.html" title="nginx中文翻译: location 指令 ">nginx中文翻译: location 指令 </a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/apache/2400.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>网站遭遇攻击</title>
		<link>http://www.crazylemon.net/web/2372.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=%25e7%25bd%2591%25e7%25ab%2599%25e9%2581%25ad%25e9%2581%2587%25e6%2594%25bb%25e5%2587%25bb</link>
		<comments>http://www.crazylemon.net/web/2372.html#comments</comments>
		<pubDate>Wed, 04 Nov 2009 18:50:40 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[虚拟主机]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[pr]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[sitemap]]></category>
		<category><![CDATA[tar]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=2372</guid>
		<description><![CDATA[一网站受到攻击，看了下，还真有意思 一、攻击时请求的都是子页面，没有请求主页，看来是预先设置或收集了目标站的sitemap 二、攻击来源IP来自全球各地，大约有两百多个，来路域名居然都是http://www.whitehouse.net 这网站像个恶搞白宫的，很早注册，PR值也达到了6，不知道是真来源，还是伪装的，不过基本可以肯定黑客的技术和资源都很不错 三、请求是通过程序处理的，所以CNZZ代码得不到本地执行，无法通过CNZZ得到统计数据 四、最高时每秒并发也只是近百，但足以让服务器响应http 500错误了 五、关了SEO URLS时（主要是去掉.htaccess的rewrite规则），情况好转，因为对方请求的是伪静态子页面，全部404 not found 六、解决办法，收集攻击来源IP，过滤下，在.htaccess里阻止掉，代码如下： &#60;Files 403.shtml&#62; order allow,deny allow from all &#60;/Files&#62; deny from XXX.XXX.XXX.XXX &#8230;&#8230; 这样做，这些来源IP的请求全部403了，哈哈 经处理，后来攻击停了，持续了5小时左右，看来对方也累 这次bluehost居然没有主动关闭空间，很是奇怪啊，CPU使用率都超高了，访问日志文件也飙得很快 相关日志05/31/2009 -- 十大WordPress的SEO优化技巧 (0)06/06/2009 -- nginx详解 (0)05/31/2009 -- SEO插件 &#8211; 20个最好的Wordpress SEO 插件 (2)08/11/2009 -- 使用Putty密钥验证自动登陆服务器 (0)08/07/2009 -- 新的google官方PR值查询接口 (2)]]></description>
			<content:encoded><![CDATA[<p>一网站受到攻击，看了下，还真有意思</p>
<p>一、攻击时请求的都是子页面，没有请求主页，看来是预先设置或收集了目标站的sitemap</p>
<p>二、攻击来源IP来自全球各地，大约有两百多个，来路域名居然都是<a href="http://www.whitehouse.net" target="_blank">http://www.whitehouse.net</a></p>
<p>这网站像个恶搞白宫的，很早注册，PR值也达到了6，不知道是真来源，还是伪装的，不过基本可以肯定黑客的技术和资源都很不错</p>
<p>三、请求是通过程序处理的，所以CNZZ代码得不到本地执行，无法通过CNZZ得到统计数据</p>
<p>四、最高时每秒并发也只是近百，但足以让服务器响应http 500错误了</p>
<p>五、关了SEO URLS时（主要是去掉.htaccess的rewrite规则），情况好转，因为对方请求的是伪静态子页面，全部404 not found</p>
<p>六、解决办法，收集攻击来源IP，过滤下，在.htaccess里阻止掉，代码如下：</p>
<p>&lt;Files 403.shtml&gt;<br />
order allow,deny<br />
allow from all<br />
&lt;/Files&gt;</p>
<p>deny from XXX.XXX.XXX.XXX<br />
&#8230;&#8230;</p>
<p>这样做，这些来源IP的请求全部403了，哈哈</p>
<p>经处理，后来攻击停了，持续了5小时左右，看来对方也累</p>
<p>这次bluehost居然没有主动关闭空间，很是奇怪啊，CPU使用率都超高了，访问日志文件也飙得很快</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>05/31/2009 -- <a href="http://www.crazylemon.net/seo/267.html" title="十大WordPress的SEO优化技巧">十大WordPress的SEO优化技巧</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>05/31/2009 -- <a href="http://www.crazylemon.net/seo/335.html" title="SEO插件 &#8211; 20个最好的Wordpress SEO 插件">SEO插件 &#8211; 20个最好的Wordpress SEO 插件</a> (2)</li><li>08/11/2009 -- <a href="http://www.crazylemon.net/linux/1561.html" title="使用Putty密钥验证自动登陆服务器">使用Putty密钥验证自动登陆服务器</a> (0)</li><li>08/07/2009 -- <a href="http://www.crazylemon.net/php/1522.html" title="新的google官方PR值查询接口">新的google官方PR值查询接口</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/web/2372.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>APMServ的rewrite配置</title>
		<link>http://www.crazylemon.net/apache/1904.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=apmserv%25e7%259a%2584rewrite%25e9%2585%258d%25e7%25bd%25ae</link>
		<comments>http://www.crazylemon.net/apache/1904.html#comments</comments>
		<pubDate>Mon, 14 Sep 2009 16:34:49 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[虚拟主机]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=1904</guid>
		<description><![CDATA[装了张宴的APMServ，发现rewrite功能不能用，查了一下，原来需要修改 E:\APMServ5.2.6\Apache\conf\httpd.conf 文件 找到你所在的虚拟目录修改以下这个地方（如果你有配置虚拟主机的话应修改E:\APMServ5.2.6\Apache\conf\apmserv\vhost.conf 文件） 找到 AllowOverride None 改成 AllowOverride Options FileInfo 重启Apache服务即可 相关日志06/06/2009 -- nginx详解 (0)05/28/2009 -- Nginx服务器安装Magento (1)07/18/2009 -- .htaccess使用指南 (0)06/17/2009 -- Linux文件查找命令find,xargs详述 (0)06/06/2009 -- Nginx的WordPress配置 (0)]]></description>
			<content:encoded><![CDATA[<p>装了张宴的APMServ，发现rewrite功能不能用，查了一下，原来需要修改</p>
<p>E:\APMServ5.2.6\Apache\conf\httpd.conf 文件</p>
<p>找到你所在的虚拟目录修改以下这个地方（如果你有配置虚拟主机的话应修改E:\APMServ5.2.6\Apache\conf\apmserv\vhost.conf 文件）</p>
<p>找到</p>
<p><span style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 宋体"><span style="COLOR: #ff0000">AllowOverride</span> None</span></p>
<p><span style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 宋体">改成</span></p>
<p><span style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 宋体"><span style="COLOR: #ff0000">AllowOverride</span> Options FileInfo</span></p>
<p><span style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 宋体">重启Apache服务即可</span></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>05/28/2009 -- <a href="http://www.crazylemon.net/nginx/211.html" title="Nginx服务器安装Magento">Nginx服务器安装Magento</a> (1)</li><li>07/18/2009 -- <a href="http://www.crazylemon.net/web/1239.html" title=".htaccess使用指南">.htaccess使用指南</a> (0)</li><li>06/17/2009 -- <a href="http://www.crazylemon.net/linux/678.html" title="Linux文件查找命令find,xargs详述">Linux文件查找命令find,xargs详述</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/apache/1904.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>301重定向进行URL标准化设置</title>
		<link>http://www.crazylemon.net/seo/1812.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=301%25e9%2587%258d%25e5%25ae%259a%25e5%2590%2591%25e8%25bf%259b%25e8%25a1%258curl%25e6%25a0%2587%25e5%2587%2586%25e5%258c%2596%25e8%25ae%25be%25e7%25bd%25ae</link>
		<comments>http://www.crazylemon.net/seo/1812.html#comments</comments>
		<pubDate>Thu, 10 Sep 2009 18:18:19 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[pr]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[虚拟主机]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=1812</guid>
		<description><![CDATA[经常会碰到这样的情况，其他网站链接你的站点时，会用下面的链接： www.crazylemon.net crazylemon.net www.crazylemon.net/index.php crazylemon.net/index.php 而这样导致：你站点主域名的pr值分散到其他几个URLs了。 如果你用301重定向把其他URL转到 www.crazylemon.net PR也就集中在主域名：www.crazylemon.net了。 301重定向具体办法： 设置.htaccess文件（只适用于linux系统，并需要虚拟主机支持。） 使访问crazylemon.net的时候就会自动转到www.crazylemon.net 在.htaccess文件里写上以下代码即可。 RewriteEngine on RewriteCond %{http_host} ^mydomain.com [NC] RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301] 注意：URL标准化的301重定向（以上代码）需要写在其他URL-rewrite代码之前。 相关日志06/06/2009 -- nginx详解 (0)07/18/2009 -- .htaccess使用指南 (0)07/08/2009 -- 分析WordPress的Rewrite机制 (0)06/06/2009 -- Nginx的WordPress配置 (0)04/23/2010 -- Cpanel开启gzip优化功能 (0)]]></description>
			<content:encoded><![CDATA[<p>经常会碰到这样的情况，其他网站链接你的站点时，会用下面的链接：</p>
<p><a href="http://www.crazylemon.net">www.crazylemon.net</a><br />
crazylemon.net<br />
<a href="http://www.crazylemon.net/index.php">www.crazylemon.net/index.php</a><br />
crazylemon.net/index.php</p>
<p>而这样导致：你站点主域名的pr值分散到其他几个URLs了。</p>
<p>如果你用301重定向把其他URL转到<br />
<a href="http://www.crazylemon.net">www.crazylemon.net</a><br />
PR也就集中在主域名：<a href="http://www.crazylemon.net">www.crazylemon.net</a>了。</p>
<p>301重定向具体办法：</p>
<p>设置.htaccess文件（只适用于linux系统，并需要虚拟主机支持。）</p>
<p>使访问crazylemon.net的时候就会自动转到<a href="http://www.crazylemon.net">www.crazylemon.net</a></p>
<p>在.htaccess文件里写上以下代码即可。</p>
<p>RewriteEngine on<br />
RewriteCond %{http_host} ^mydomain.com [NC]<br />
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]</p>
<p>注意：URL标准化的301重定向（以上代码）需要写在其他URL-rewrite代码之前。</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>07/18/2009 -- <a href="http://www.crazylemon.net/web/1239.html" title=".htaccess使用指南">.htaccess使用指南</a> (0)</li><li>07/08/2009 -- <a href="http://www.crazylemon.net/wordpress/1050.html" title="分析WordPress的Rewrite机制">分析WordPress的Rewrite机制</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>04/23/2010 -- <a href="http://www.crazylemon.net/apache/3111.html" title="Cpanel开启gzip优化功能">Cpanel开启gzip优化功能</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/seo/1812.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP</title>
		<link>http://www.crazylemon.net/apache/1796.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=apache%25e6%259c%258d%25e5%258a%25a1%25e5%2599%25a8wordpress%25e8%25ae%25be%25e7%25bd%25ae%25e6%25b0%25b8%25e4%25b9%2585%25e8%25bf%259e%25e6%258e%25a5%25e5%2590%258e%25e6%2580%258e%25e4%25b9%2588%25e5%258e%25bb%25e6%258e%2589index-php</link>
		<comments>http://www.crazylemon.net/apache/1796.html#comments</comments>
		<pubDate>Wed, 09 Sep 2009 17:36:51 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[pr]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[word]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=1796</guid>
		<description><![CDATA[在网站根目录下创建.htaccess文件，加入下列内容 # BEGIN WordPres &#60;IfModule mod_rewrite.c&#62; RewriteEngine On RewriteBase /wordpress RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L] &#60;/IfModule&#62; # END WordPress wordpress需要改为你自己的wordpress文件夹的名字，如果是主目录下，就不必了，直接干掉 即可 原来我错了，从nginx服务器搬过来时，忘了没有.htaccess文件，导致除了主页都无法访问 难怪IP少了好多。。。晕死 相关日志06/06/2009 -- Nginx的WordPress配置 (0)07/08/2009 -- 分析WordPress的Rewrite机制 (0)06/06/2009 -- nginx详解 (0)07/18/2009 -- .htaccess使用指南 (0)07/10/2009 -- nginx rewrite 参数 (0)]]></description>
			<content:encoded><![CDATA[<p>在网站根目录下创建.htaccess文件，加入下列内容</p>
<p># BEGIN WordPres<br />
&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine On<br />
RewriteBase /wordpress<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule . /wordpress/index.php [L]<br />
&lt;/IfModule&gt;<br />
# END WordPress</p>
<p>wordpress需要改为你自己的wordpress文件夹的名字，如果是主目录下，就不必了，直接干掉</p>
<p>即可</p>
<p>原来我错了，从nginx服务器搬过来时，忘了没有.htaccess文件，导致除了主页都无法访问</p>
<p>难怪IP少了好多。。。晕死</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>07/08/2009 -- <a href="http://www.crazylemon.net/wordpress/1050.html" title="分析WordPress的Rewrite机制">分析WordPress的Rewrite机制</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>07/18/2009 -- <a href="http://www.crazylemon.net/web/1239.html" title=".htaccess使用指南">.htaccess使用指南</a> (0)</li><li>07/10/2009 -- <a href="http://www.crazylemon.net/nginx/1096.html" title="nginx rewrite 参数">nginx rewrite 参数</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/apache/1796.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>nginx rewrite 参数</title>
		<link>http://www.crazylemon.net/nginx/1096.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=nginx-rewrite-%25e5%258f%2582%25e6%2595%25b0</link>
		<comments>http://www.crazylemon.net/nginx/1096.html#comments</comments>
		<pubDate>Fri, 10 Jul 2009 17:25:01 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[pr]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[rm]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[space]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=1096</guid>
		<description><![CDATA[正则表达式匹配，其中： * ~ 为区分大小写匹配 * ~* 为不区分大小写匹配 * !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 文件及目录匹配，其中： * -f和!-f用来判断是否存在文件 * -d和!-d用来判断是否存在目录 * -e和!-e用来判断是否存在文件或目录 * -x和!-x用来判断文件是否可执行 flag标记有： * last 相当于Apache里的[L]标记，表示完成rewrite * break 终止匹配, 不再匹配后面的规则 * redirect 返回302临时重定向 * permanent 返回301永久重定向 一些可用的全局变量有，可以用做条件判断(待补全) $args $content_length $content_type $document_root $document_uri $host $http_user_agent $http_cookie $limit_rate $request_body_file $request_method $remote_addr $remote_port $remote_user $request_filename $request_uri $query_string $scheme $server_protocol $server_addr $server_name $server_port [...]]]></description>
			<content:encoded><![CDATA[<p>正则表达式匹配，其中：</p>
<p>* ~ 为区分大小写匹配<br />
* ~* 为不区分大小写匹配<br />
* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配</p>
<p>文件及目录匹配，其中：</p>
<p>* -f和!-f用来判断是否存在文件<br />
* -d和!-d用来判断是否存在目录<br />
* -e和!-e用来判断是否存在文件或目录<br />
* -x和!-x用来判断文件是否可执行</p>
<p>flag标记有：</p>
<p>* last 相当于Apache里的[L]标记，表示完成rewrite<br />
* break 终止匹配, 不再匹配后面的规则<br />
* redirect 返回302临时重定向<br />
* permanent 返回301永久重定向</p>
<p>一些可用的全局变量有，可以用做条件判断(待补全)</p>
<p>$args<br />
$content_length<br />
$content_type<br />
$document_root<br />
$document_uri<br />
$host<br />
$http_user_agent<br />
$http_cookie<br />
$limit_rate<br />
$request_body_file<br />
$request_method<br />
$remote_addr<br />
$remote_port<br />
$remote_user<br />
$request_filename<br />
$request_uri<br />
$query_string<br />
$scheme<br />
$server_protocol<br />
$server_addr<br />
$server_name<br />
$server_port<br />
$uri</p>
<p>结合QeePHP的例子</p>
<p>if (!-d $request_filename) {<br />
rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&amp;controller=$1&amp;action=$2&amp;$3 last;<br />
rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&amp;controller=$1 last;<br />
break;<br />
}</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>06/16/2009 -- <a href="http://www.crazylemon.net/nginx/670.html" title="nginx.conf &#8211; nginx配置文件说明">nginx.conf &#8211; nginx配置文件说明</a> (1)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>06/03/2009 -- <a href="http://www.crazylemon.net/php/416.html" title="Nginx的UrlRewrite配置">Nginx的UrlRewrite配置</a> (0)</li><li>05/28/2009 -- <a href="http://www.crazylemon.net/nginx/211.html" title="Nginx服务器安装Magento">Nginx服务器安装Magento</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/1096.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>分析WordPress的Rewrite机制</title>
		<link>http://www.crazylemon.net/wordpress/1050.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=%25e5%2588%2586%25e6%259e%2590wordpress%25e7%259a%2584rewrite%25e6%259c%25ba%25e5%2588%25b6</link>
		<comments>http://www.crazylemon.net/wordpress/1050.html#comments</comments>
		<pubDate>Wed, 08 Jul 2009 19:08:57 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[pr]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[word]]></category>
		<category><![CDATA[搜索引擎]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=1050</guid>
		<description><![CDATA[家都知道，WordPress 可以通过 Apache 的 mod_rewrite 模块，使用 .htaccess 文件来重写URL，生成静态链接(或称永久链接)，如 http://example.com/年/月/日/日志名/ ，使URL更加美观也对搜索引擎更友好。但具体是如何实现的，可能有些朋友不是很清楚，因此我在这里稍稍阐述下。而在不支持 .htaccess 的主机环境中，也可以使用 http://example.com/index.php/年/月/日/日志名/ 这种形式的URL，以及使用ISAPI等东东，原理都差不多，本文就不探讨了。 我以 http://www.crazylemon.net/database-dict-for-wordpress-23/2008/02/25/ 为具体例子进行分析。首先我们先来看看WordPress根目录下的 .htaccess 文件，其中有一段如下 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] 意思是指，当接收到的请求不是一个文件或目录时，则会重写为WordPress根目录下的index.php文件，然后 index.php 就开始处理请求。 index.php 会包含 wp-blog-header.php， wp-blog-header.php 会包含 wp-config.php， wp-config.php 又会包含 wp-settings.php，最后 wp-settings.php 会包含一大堆文件进来，晕了吧。其中， wp-includes/query.php 中的 WP_Query 类和 wp-includes/classes.php 中的 WP 类是Rewrite最主要的，因此我们将对象实例化 $wp_the_query =&#38;amp; new WP_Query(); [...]]]></description>
			<content:encoded><![CDATA[<p>家都知道，WordPress 可以通过 Apache 的 mod_rewrite 模块，使用 .htaccess 文件来重写URL，生成静态链接(或称永久链接)，如 http://example.com/年/月/日/日志名/ ，使URL更加美观也对搜索引擎更友好。但具体是如何实现的，可能有些朋友不是很清楚，因此我在这里稍稍阐述下。而在不支持 .htaccess 的主机环境中，也可以使用 http://example.com/index.php/年/月/日/日志名/ 这种形式的URL，以及使用ISAPI等东东，原理都差不多，本文就不探讨了。</p>
<p>我以 http://www.crazylemon.net/database-dict-for-wordpress-23/2008/02/25/ 为具体例子进行分析。首先我们先来看看WordPress根目录下的 .htaccess 文件，其中有一段如下</p>
<p><code>RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule . /index.php [L]</code></p>
<p>意思是指，当接收到的请求不是一个文件或目录时，则会重写为WordPress根目录下的index.php文件，然后 index.php 就开始处理请求。</p>
<p>index.php 会包含 wp-blog-header.php， wp-blog-header.php 会包含 wp-config.php， wp-config.php 又会包含 wp-settings.php，最后 wp-settings.php 会包含一大堆文件进来，晕了吧。其中， wp-includes/query.php 中的 WP_Query 类和 wp-includes/classes.php 中的 WP 类是Rewrite最主要的，因此我们将对象实例化</p>
<p><code>$wp_the_query =&amp;amp; new WP_Query();<br />
$wp_query     =&amp;amp; $wp_the_query;<br />
$wp_rewrite   =&amp;amp; new WP_Rewrite();<br />
$wp           =&amp;amp; new WP();</code></p>
<p>做了这么多准备工作后，WP真正开始处理请求了，在 wp-blog-header.php 中调用wp()函数，在这个函数执行了 WP 类的成员方法main()</p>
<p><code>function main($query_args = ”) {<br />
    $this-&amp;gt;init(); //初始化，获取当前用户信息<br />
    $this-&amp;gt;parse_request($query_args); //解析请求<br />
    $this-&amp;gt;send_headers(); //发送头信息<br />
    $this-&amp;gt;query_posts(); //查询日志<br />
    $this-&amp;gt;handle_404(); //操作404(URL地址不存在)<br />
    $this-&amp;gt;register_globals(); //注册全局变量<br />
    do_action_ref_array(’wp’, array(&amp;amp;$this));<br />
}</code></p>
<p>我们进入$this-&gt;parse_request()瞧瞧，通过$_SERVER[’REQUEST_URI’]和过滤得到字符串 ‘database-dict-for-wordpress-23/2008/02/25′ 赋值给$request_match，与存储在数据库中的rewrite规则集进行正则匹配，rewrite规则集类似与下面这个样子，当然，比下面的多了很多。</p>
<p><code>[wp-feed.php$] =&amp;gt; index.php?feed=feed<br />
[wp-commentsrss2.php$] =&amp;gt; index.php?feed=rss2&amp;amp;withcomments=1<br />
[(about)/trackback/?$] =&amp;gt; index.php?pagename=$matches[1]&amp;amp;tb=1<br />
[page/?([0-9]{1,})/?$] =&amp;gt; index.php?&amp;amp;paged=$matches[1]<br />
[comments/(feed|rdf|rss|rss2|atom)/?$] =&amp;gt; index.php?&amp;amp;feed=$matches[1]&amp;amp;withcomments=1<br />
[search/(.+)/?$] =&amp;gt; index.php?s=$matches[1]<br />
[category/(.+?)/?$] =&amp;gt; index.php?category_name=$matches[1]<br />
[tag/(.+?)/?$] =&amp;gt; index.php?tag=$matches[1]</code></p>
<p>我的请求与 ‘([^/]+)/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})(/[0-9]+)?/?$’ 这条匹配，所以我的请求被转化为 ‘name=database-dict-for-wordpress-23&amp;year=2008&amp;monthnum=02&amp;day=25&amp;page=’，如果请求都没匹配上那就肯定404了。接着就是通过 $this-&gt;query_posts() 来查询日志信息了，查询不到那还是404，废话…</p>
<p>把这些都整完了，回到 wp-blog-header.php，包含 wp-includes/template-loader.php 来加载模板并显示，日志显示日志，页面显示页面，404显示404，总之就是各神归位，OVER</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>06/04/2009 -- <a href="http://www.crazylemon.net/seo/438.html" title="wordpress ping服务">wordpress ping服务</a> (2)</li><li>09/10/2009 -- <a href="http://www.crazylemon.net/apache/1796.html" title="Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP">Apache服务器wordpress设置永久连接后怎么去掉INDEX.PHP</a> (1)</li><li>11/07/2009 -- <a href="http://www.crazylemon.net/apache/2400.html" title="Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式">Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式</a> (6)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/wordpress/1050.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>osCommerce 在 nginx 上的 rewrite 规则</title>
		<link>http://www.crazylemon.net/nginx/620.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=oscommerce-%25e5%259c%25a8-nginx-%25e4%25b8%258a%25e7%259a%2584-rewrite-%25e8%25a7%2584%25e5%2588%2599</link>
		<comments>http://www.crazylemon.net/nginx/620.html#comments</comments>
		<pubDate>Fri, 12 Jun 2009 15:39:53 +0000</pubDate>
		<dc:creator>CrazyLemon</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[pr]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[rm]]></category>
		<category><![CDATA[vi]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.crazylemon.net/?p=620</guid>
		<description><![CDATA[location / {  if (!-e $request_filename)  { rewrite &#8220;^(.*)-p-(.*).html&#8221; /product_info.php?products_id=$2%1; rewrite &#8220;^(.*)-p-(.*).html&#8221; /product_info.php?products_id=$2&#38;% last; rewrite &#8220;^(.*)-c-(.*).html&#8221; /index.php?cPath=$2&#38;% last; rewrite &#8220;^(.*)-m-(.*).html&#8221; /index.php?manufacturers_id=$2&#38;% last; rewrite &#8220;^(.*)-pi-(.*).html&#8221; /popup_image.php?pID=$2&#38;% last; rewrite &#8220;^(.*)-t-(.*).html&#8221; /articles.php?tPath=$2&#38;% last; rewrite &#8220;^(.*)-au-(.*).html&#8221; /articles.php?authors_id=$2&#38;% last; rewrite &#8220;^(.*)-a-(.*).html&#8221; /article_info.php?articles_id=$2&#38;% last; rewrite &#8220;^(.*)-pr-(.*).html&#8221; /product_reviews.php?products_id=$2&#38;% last; rewrite &#8220;^(.*)-pri-(.*).html&#8221; /product_reviews_info.php?products_id=$2&#38;% last; rewrite &#8220;^(.*)-i-(.*).html&#8221; /information.php?info_id=$2&#38;% last; rewrite &#8220;^(.*)-pm-([0-9]+).html&#8221; /info_pages.php?pages_id=$2&#38;% last; rewrite [...]]]></description>
			<content:encoded><![CDATA[<p>location / {<br />
 if (!-e $request_filename)<br />
 {<br />
rewrite &#8220;^(.*)-p-(.*).html&#8221; /product_info.php?products_id=$2%1;<br />
rewrite &#8220;^(.*)-p-(.*).html&#8221; /product_info.php?products_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-c-(.*).html&#8221; /index.php?cPath=$2&amp;% last;<br />
rewrite &#8220;^(.*)-m-(.*).html&#8221; /index.php?manufacturers_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-pi-(.*).html&#8221; /popup_image.php?pID=$2&amp;% last;<br />
rewrite &#8220;^(.*)-t-(.*).html&#8221; /articles.php?tPath=$2&amp;% last;<br />
rewrite &#8220;^(.*)-au-(.*).html&#8221; /articles.php?authors_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-a-(.*).html&#8221; /article_info.php?articles_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-pr-(.*).html&#8221; /product_reviews.php?products_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-pri-(.*).html&#8221; /product_reviews_info.php?products_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-i-(.*).html&#8221; /information.php?info_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-pm-([0-9]+).html&#8221; /info_pages.php?pages_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-links-(.*).html&#8221; /links.php?lPath=$2&amp;% last;<br />
rewrite &#8220;^(.*)-n-(.*).html&#8221; /newsdesk_info.php?newsdesk_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-nc-(.*).html&#8221; /newsdesk_index.php?newsPath=$2&amp;% last;<br />
rewrite &#8220;^(.*)-nri-(.*).html&#8221; /newsdesk_reviews_info.php?newsdesk_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-nra-(.*).html&#8221; /newsdesk_reviews_article.php?newsdesk_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-f-(.*).html&#8221; /faqdesk_info.php?faqdesk_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-fc-(.*).html&#8221; /faqdesk_index.php?faqPath=$2&amp;% last;<br />
rewrite &#8220;^(.*)-fri-(.*).html&#8221; /faqdesk_reviews_info.php?faqdesk_id=$2&amp;% last;<br />
rewrite &#8220;^(.*)-fra-(.*).html&#8221; /faqdesk_reviews_article.php?faqdesk_id=$2&amp;% last;<br />
 }<br />
}</p>
<p>相应的apache为：</p>
<p>RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2%1<br />
RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-pi-(.*).html$ popup_image.php?pID=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-t-(.*).html$ articles.php?tPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-au-(.*).html$ articles.php?authors_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-a-(.*).html$ article_info.php?articles_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-pr-(.*).html$ product_reviews.php?products_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-pri-(.*).html$ product_reviews_info.php?products_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-i-(.*).html$ information.php?info_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-pm-([0-9]+).html$ info_pages.php?pages_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-links-(.*).html$ links.php?lPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-n-(.*).html$ newsdesk_info.php?newsdesk_id=$2&amp;%{QUERY_STRING}</p>
<p>RewriteRule ^(.*)-nc-(.*).html$ newsdesk_index.php?newsPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-nri-(.*).html$ newsdesk_reviews_info.php?newsdesk_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-nra-(.*).html$ newsdesk_reviews_article.php?newsdesk_id=$2&amp;%{QUERY_STRING}</p>
<p>RewriteRule ^(.*)-f-(.*).html$ faqdesk_info.php?faqdesk_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-fc-(.*).html$ faqdesk_index.php?faqPath=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-fri-(.*).html$ faqdesk_reviews_info.php?faqdesk_id=$2&amp;%{QUERY_STRING}<br />
RewriteRule ^(.*)-fra-(.*).html$ faqdesk_reviews_article.php?faqdesk_id=$2&amp;%{QUERY_STRING}</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" target="_blank"><img src="http://www.crazylemon.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/510.html" title="nginx详解">nginx详解</a> (0)</li><li>06/06/2009 -- <a href="http://www.crazylemon.net/nginx/504.html" title="Nginx的WordPress配置">Nginx的WordPress配置</a> (0)</li><li>05/28/2009 -- <a href="http://www.crazylemon.net/nginx/211.html" title="Nginx服务器安装Magento">Nginx服务器安装Magento</a> (1)</li><li>11/07/2009 -- <a href="http://www.crazylemon.net/apache/2400.html" title="Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式">Apache mod_rewrite模块中RewriteCond和RewriteRule的指令格式</a> (6)</li><li>06/03/2009 -- <a href="http://www.crazylemon.net/php/416.html" title="Nginx的UrlRewrite配置">Nginx的UrlRewrite配置</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.crazylemon.net/nginx/620.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
