<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[Apache中 RewriteCond 规则参数介绍]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 25 Aug 2010 09:45:02 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apache中 RewriteCond语句对于我来说一直是个难点，多次试图去把它搞明白，都没有结构，这次我终于算大概知道它的意思了。<br/>&nbsp;&nbsp; RewriteCond就像我们程序中的if语句一样，表示如果符合某个或某几个条件则执行RewriteCond下面紧邻的RewriteRule语句，这就是RewriteCond最原始、基础的功能，为了方便理解，下面来看看几个例子。<br/>&nbsp;&nbsp; RewriteEngine on<br/>&nbsp;&nbsp; RewriteCond&nbsp;&nbsp;%&#123;HTTP_USER_AGENT&#125;&nbsp;&nbsp;^Mozilla&#92;/5&#92;.0.*<br/>&nbsp;&nbsp; RewriteRule&nbsp;&nbsp;index.php&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index.m.php<br/> <br/>&nbsp;&nbsp; RewriteCond&nbsp;&nbsp;%&#123;HTTP_USER_AGENT&#125;&nbsp;&nbsp;^Lynx.*<br/>&nbsp;&nbsp; RewriteRule&nbsp;&nbsp;index.php&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index.L.php <br/><br/>&nbsp;&nbsp; RewriteRule&nbsp;&nbsp;index.php&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index.b.php<br/>上面语句的作用是当你是用FF浏览器访问index.php这个文件的时候，会自动让你访问到index.m.php这个文件，当你是用一些移动终端访问的时候，会让你对index.php这个文件的访问实际访问的是index.L.php去，如果你是用其它的浏览器访问的时候，会让你跳到 index.b.php。在说形象一点，上面的语句就等同于程序里面的下面语句(依PHP语句为例):<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($_SERVER[&#039;HTTP_USER_AGENT&#039;] == &#039;Mozilla/5.0&#039;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//跳转到对index.m.php的访问<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if($_SERVER[&#039;HTTP_USER_AGENT&#039;] == &#039;Lynx&#039;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//跳转到对index.L.php的访问<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//跳转到对index.b.php的访问<br/> <br/> 在看例2：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RewriteCond %&#123;HTTP_REFERER&#125; (www.test.cn)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RewriteRule (.*)$ test.php<br/>上面语句的作用是如果你访问的上一个页面的主机地址是www.test.cn，则无论你当前访问的是哪个页面，都会跳转到对test.php的访问。<br/><br/>在看例三：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RewriteCond %&#123;REMOTE_HOST&#125; ^host1.* [OR]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RewriteCond %&#123;REMOTE_HOST&#125; ^host2.* [OR]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RewriteCond %&#123;REMOTE_HOST&#125; ^host3.*<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RewriteRule (.*)$ test.php<br/>上面语句的作用是如果你的地址是host1或host2或host3的时候，则就跳到对test.php。从这里可以看出，RewriteCond语句之间默认的是AND,如果想要OR,则要明确的写出来。<br/><br/>下面是自己收藏的一些有用的重写规则：<br/>RewriteCond %&#123;REQUEST_FILENAME&#125; !-f&nbsp;&nbsp; //如果文件存在，就直接访问文件，不进行下面的RewriteRule.(不是文件或文件不存在就执行重写)<br/><br/>RewriteCond %&#123;REQUEST_FILENAME&#125; !-d&nbsp;&nbsp; //#如果目录存在就直接访问目录不进行RewriteRule<br/><br/>RewriteCond %&#123;REQUEST_URI&#125; !^.*(&#92;.css&#124;&#92;.js&#124;&#92;.gif&#124;&#92;.png&#124;&#92;.jpg&#124;&#92;.jpeg)$ //#如果是这些后缀的文件，就直接访问文件，不进行Rewrite<br/><br/>来源：http://www.mx111.com/Article_View.asp?id=1347
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] Apache中 RewriteCond 规则参数介绍]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>