<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[静怡家园]]></title> 
<link>http://www.zhanghaijun.com/index.php</link> 
<description><![CDATA[书山有路勤为径，学海无涯苦作舟！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[静怡家园]]></copyright>
<item>
<link>http://www.zhanghaijun.com/post//</link>
<title><![CDATA[WEB开发人员应该知道的24则Apache Rewrite规则]]></title> 
<author>碟舞飞扬 &lt;webmaster@zhanghaijun.com&gt;</author>
<category><![CDATA[服务器类]]></category>
<pubDate>Sat, 14 May 2011 18:40:09 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//</guid> 
<description>
<![CDATA[ 
	1、防盗链<br/><br/>Options +FollowSymlinks<br/> #Protect against hotlinking<br/> RewriteEngine On<br/> RewriteCond %{HTTP_REFERER} !^$<br/> RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]<br/> RewriteRule .*.(gif&#124;jpg&#124;png)$ http://domainname.com/img/stop_stealing_bandwidth.gif[nc]<br/> <br/>2、通过User Agents 禁止访问 <br/><br/>#Block bad bots<br/> SetEnvIfNoCase user-Agent ^FrontPage [NC,OR]<br/> SetEnvIfNoCase user-Agent ^Java.* [NC,OR]<br/> SetEnvIfNoCase user-Agent ^Microsoft.URL [NC,OR]<br/> SetEnvIfNoCase user-Agent ^MSFrontPage [NC,OR]<br/> SetEnvIfNoCase user-Agent ^Offline.Explorer [NC,OR]<br/> SetEnvIfNoCase user-Agent ^[Ww]eb[Bb]andit [NC,OR]<br/> SetEnvIfNoCase user-Agent ^Zeus [NC]<br/> &lt;limit get=&quot;&quot; post=&quot;&quot; head=&quot;&quot;&gt;<br/> Order Allow,Deny<br/> Allow from all<br/> Deny from env=bad_bot<br/> &lt;/limit&gt;<br/> <br/>3、重定向（禁止）所有访问，某些来源IP除外 <br/><br/>ErrorDocument 403 http://www.domainname.com<br/> Order deny,allow<br/> Deny from all<br/> Allow from 124.34.48.165<br/> Allow from 102.54.68.123<br/> <br/>4、SEO 友好 301 重定向 <br/><br/>Redirect 301 /d/file.html http://www.domainname.com/r/file.html<br/> <br/>5、自定义错误页面 <br/><br/>ErrorDocument 401 /error/401.php<br/> ErrorDocument 403 /error/403.php<br/> ErrorDocument 404 /error/404.php<br/> ErrorDocument 500 /error/500.php<br/> <br/>6、禁止某些来源IP <br/><br/>allow from all<br/> deny from 145.186.14.122<br/> deny from 124.15<br/> <br/>7、设置服务器管理员的默认邮箱地址 <br/><br/>ServerSignature EMail<br/> SetEnv SERVER_ADMIN default@domain.com<br/> <br/>8、禁用显示下载请求 <br/><br/>AddType application/octet-stream .pdf<br/> AddType application/octet-stream .zip<br/> AddType application/octet-stream .mov<br/> <br/>9、保护特定的文件，禁止访问。 <br/><br/>#Protect the .htaccess File<br/> &lt;files .htaccess=&quot;&quot;&gt;<br/> order allow,deny<br/> deny from all<br/> &lt;/files&gt;<br/> <br/>10、利用mod_deflate压缩文件 <br/><br/>&lt;ifmodule mod_deflate.c=&quot;&quot;&gt;<br/> &lt;filesmatch .(js&#124;css)$=&quot;&quot;&gt;<br/> SetOutputFilter DEFLATE<br/> &lt;/filesmatch&gt;<br/> &lt;/ifmodule&gt;<br/> <br/>11、添加Expires头 <br/><br/>&lt;filesmatch .(ico&#124;pdf&#124;flv&#124;jpg&#124;jpeg&#124;png&#124;gif&#124;swf)$=&quot;&quot;&gt;<br/> Header set Expires &quot;Wed, 21 May 2010 20:00:00 GMT&quot;<br/> &lt;/filesmatch&gt;<br/> <br/>12、设置默认页 <br/><br/>#Serve Alternate Default Index Page<br/> DirectoryIndex about.html<br/> <br/>13、设置密码保护文件和目录 <br/><br/>#password-protect a file<br/> &lt;files secure.php=&quot;&quot;&gt;<br/> AuthType Basic<br/> AuthName &quot;Prompt&quot;<br/> AuthUserFile /home/path/.htpasswd<br/> Require valid-user<br/> &lt;/files&gt;<br/> <br/># password-protect a directory<br/> resides<br/> AuthType basic<br/> AuthName &quot;This directory is protected&quot;<br/> AuthUserFile /home/path/.htpasswd<br/> AuthGroupFile /dev/null<br/> Require valid-user<br/> <br/>14、将老域名重定向新域名 <br/><br/>#Redirect from an old domain to a new domain<br/> RewriteEngine On<br/> RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301,L]<br/> <br/>15、强制缓存 <br/><br/>FileETag MTime Size<br/> ExpiresActive on<br/> ExpiresDefault &quot;access plus 86400 seconds&quot;<br/> <br/>16、启用GZIP压缩相关文件 <br/><br/>AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript<br/> BrowserMatch ^Mozilla/4 gzip-only-text/html<br/> BrowserMatch ^Mozilla/4.0[678] no-gzip<br/> <br/>BrowserMatch bMSIE !no-gzip !gzip-only-text/html<br/> <br/>17、从URL中移除“category” <br/><br/>RewriteRule ^category/(.+)$ http://www.yourdomain.com/$1 [R=301,L]<br/> <br/>18、禁止目录浏览 <br/><br/>Options All -Indexes<br/> <br/>19、重定向WordPress的订阅到Feedburner <br/><br/>#Redirect wordpress content feeds to feedburner<br/> &lt;ifmodule mod_rewrite.c=&quot;&quot;&gt;<br/> RewriteEngine on<br/> RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]<br/> RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]<br/> RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/yourfeed [R=302,NC,L]<br/> &lt;/ifmodule&gt;<br/> <br/>20、禁止空Referrer访问内容 <br/><br/>RewriteEngine On<br/> RewriteCond %{REQUEST_METHOD} POST<br/> RewriteCond %{REQUEST_URI} .wp-comments-post.php*<br/> RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]<br/> RewriteCond %{HTTP_USER_AGENT} ^$<br/> RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]<br/> <br/>21、从URL中删除文件扩展名 <br/><br/>RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]<br/> <br/>22、将www.domain.com重定向到domain.com<br/><br/>#remove www from URI<br/> RewriteEngine On<br/> RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]<br/> RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]<br/> <br/>23、URL结尾添加/ <br/><br/>#trailing slash enforcement<br/> RewriteBase /<br/> RewriteCond %{REQUEST_FILENAME} !-f<br/> RewriteCond %{REQUEST_URI} !#<br/> RewriteCond %{REQUEST_URI} !(.*)/$<br/> RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301<br/> <br/>24、将www.domain.com/xxx重定向到domain.com/xxx <br/><br/># Redirect if www.yourdomain.com to yourdomain.com<br/> RewriteCond %{HTTP_HOST} ^www.example.com [NC]<br/> RewriteRule (.*) http://example.com/$1 [R=301,L]<br/>Tags - <a href="http://www.zhanghaijun.com/tags/apache/" rel="tag">apache</a> , <a href="http://www.zhanghaijun.com/tags/rewrite/" rel="tag">rewrite</a>
]]>
</description>
</item><item>
<link>http://www.zhanghaijun.com/post//#blogcomment</link>
<title><![CDATA[[评论] WEB开发人员应该知道的24则Apache Rewrite规则]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>