<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Y's Blog]]></title> 
<link>http://blog.sust.net.ru/index.php</link> 
<description><![CDATA[sust 陕西科技大学 科大漂亮MM该来的 Blog-网络红人的博客]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Y's Blog]]></copyright>
<item>
<link>http://blog.sust.net.ru/read.php?</link>
<title><![CDATA[.htaccess 学习笔记]]></title> 
<author>pling &lt;admin@oneter.com&gt;</author>
<category><![CDATA[学习与实践]]></category>
<pubDate>Fri, 28 Jul 2006 15:55:39 +0000</pubDate> 
<guid>http://blog.sust.net.ru/read.php?</guid> 
<description>
<![CDATA[ 
	.htaccess可以做大量范围的事情，包括：文件夹密码保护、用户自动重新指向、自定义错误页面、变更你的文件扩展名、屏蔽特定的用户IP地址、只允许特定的IP地址、停止目录表以及使用其他文件作为index文件，等等......<br/><br/>1. Introduction 介绍<br/>文件名 .htaccess 属性 644 (RW-R–R–)<br/>htaccess会影响它所在目录下的所有子目录<br/>注意大多数内容都要求保持在一行之内，不要换行，否则会引起错误<br/><br/>2. Error Documents 错误文档<br/>Official document: ErrorDocument Directive<br/>ErrorDocument code document<br/>例子<br/>ErrorDocument 400 /errors/badrequest.html<br/>ErrorDocument 404 <a href="http://yoursite/errors/notfound.html" target="_blank">http://yoursite/errors/notfound.html</a><br/>ErrorDocument 401 “Authorization Required”<br/>(注意之后内容如果出现的双引号需要转义为 &#92;”)<br/>常见HTTP状态码<br/>Successful Client Requests<br/>200 OK<br/>201 Created<br/>202 Accepted<br/>203 Non-Authorative Information<br/>204 No Content<br/>205 Reset Content<br/>206 Partial Content<br/>Client Request Redirected<br/>300 Multiple Choices<br/>301 Moved Permanently<br/>302 Moved Temporarily<br/>303 See Other<br/>304 Not Modified<br/>305 Use Proxy<br/>Client Request Errors<br/>400 Bad Request<br/>401 Authorization Required<br/>402 Payment Required (not used yet)<br/>403 Forbidden<br/>404 Not Found<br/>405 Method Not Allowed<br/>406 Not Acceptable (encoding)<br/>407 Proxy Authentication Required<br/>408 Request Timed Out<br/>409 Conflicting Request<br/>410 Gone<br/>411 Content Length Required<br/>412 Precondition Failed<br/>413 Request Entity Too Long<br/>414 Request URI Too Long<br/>415 Unsupported Media Type<br/>Server Errors<br/>500 Internal Server Error<br/>501 Not Implemented<br/>502 Bad Gateway<br/>503 Service Unavailable<br/>504 Gateway Timeout<br/>505 HTTP Version Not Supported<br/><br/>3. Password Protection 密码保护<br/>Official document: Authentication, Authorization and Access Control<br/>假设密码文件为.htpasswd<br/>AuthUserFile /usr/local/safedir/.htpasswd (这里必须使用全路径名)<br/>AuthName EnterPassword<br/>AuthType Basic<br/>两种常见验证方式:<br/>Require user windix<br/>(仅允许用户windix登陆)<br/>Require valid-user<br/>(所有合法用户都可登陆)<br/>Tip: 如何生成密码文件<br/>使用htpasswd命令(apache自带)<br/>第一次生成需要创建密码文件<br/>htpasswd -c .htpasswd user1<br/>之后增加新用户<br/>htpasswd .htpasswd user2<br/><br/>4. Enabling SSI Via htaccess 通过htaccess允许SSI(Server Side Including)功能<br/>AddType text/html .shtml<br/>AddHandler server-parsed .shtml<br/>Options Indexes FollowSymLinks Includes<br/>DirectoryIndex index.shtml index.html<br/><br/>5. Blocking users by IP 根据IP阻止用户访问<br/>order allow,deny<br/>deny from 123.45.6.7<br/>deny from 12.34.5. (整个C类地址)<br/>allow from all<br/><br/>6. Blocking users/sites by referrer 根据referrer阻止用户/站点访问<br/>需要mod_rewrite模块<br/>例1. 阻止单一referrer: badsite.com<br/>RewriteEngine on<br/># Options +FollowSymlinks<br/>RewriteCond %{HTTP_REFERER} badsite&#92;.com [NC]<br/>RewriteRule .* - [F]<br/>例2. 阻止多个referrer: badsite1.com, badsite2.com<br/>RewriteEngine on<br/># Options +FollowSymlinks<br/>RewriteCond %{HTTP_REFERER} badsite1&#92;.com [NC,OR]<br/>RewriteCond %{HTTP_REFERER} badsite2&#92;.com<br/>RewriteRule .* - [F]<br/>[NC] - 大小写不敏感(Case-insensite)<br/>[F] - 403 Forbidden<br/>注意以上代码注释掉了”Options +FollowSymlinks”这个语句。如果服务器未在 httpd.conf 的 段落设置 FollowSymLinks, 则需要加上这句，否则会得到”500 Internal Server error”错误。<br/><br/>7. Blocking bad bots and site rippers (aka offline browsers) 阻止坏爬虫和离线浏览器<br/>需要mod_rewrite模块<br/>坏爬虫? 比如一些抓垃圾email地址的爬虫和不遵守robots.txt的爬虫(如baidu?)<br/>可以根据 HTTP_USER_AGENT 来判断它们<br/>(但是还有更无耻的如”中搜 zhongsou.com”之流把自己的agent设置为 “Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)” 太流氓了，就无能为力了)<br/>RewriteEngine On<br/>RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Bot&#92; mailto:craftbot@yahoo.com [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Download&#92; Demon [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Express&#92; WebPictures [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]<br/>RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Image&#92; Stripper [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Image&#92; Sucker [OR]<br/>RewriteCond %{HTTP_USER_AGENT} Indy&#92; Library [NC,OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Internet&#92; Ninja [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^JOC&#92; Web&#92; Spider [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Mass&#92; Downloader [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^MIDown&#92; tool [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Mister&#92; PiX [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Net&#92; Vampire [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Offline&#92; Explorer [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Offline&#92; Navigator [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Papa&#92; Foto [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Teleport&#92; Pro [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Web&#92; Image&#92; Collector [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Web&#92; Sucker [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebGo&#92; IS [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Website&#92; eXtractor [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Website&#92; Quester [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Xaldon&#92; WebSpider [OR]<br/>RewriteCond %{HTTP_USER_AGENT} ^Zeus<br/>RewriteRule ^.* - [F,L]<br/>[F] - 403 Forbidden<br/>[L] - ?<br/><br/>8. Change your default directory page 改变缺省目录页面<br/>DirectoryIndex index.html index.php index.cgi index.pl<br/><br/>9. Redirects 转向<br/>单个文件<br/>Redirect /old_dir/old_file.html <a href="http://yoursite.com/new_dir/new_file.html" target="_blank">http://yoursite.com/new_dir/new_file.html</a><br/>整个目录<br/>Redirect /old_dir <a href="http://yoursite.com/new_dir" target="_blank">http://yoursite.com/new_dir</a><br/>效果: 如同将目录移动位置一样<br/><a href="http://yoursite.com/old_dir" target="_blank">http://yoursite.com/old_dir</a> -> <a href="http://yoursite.com/new_dir" target="_blank">http://yoursite.com/new_dir</a><br/><a href="http://yoursite.com/old_dir/dir1/test.html" target="_blank">http://yoursite.com/old_dir/dir1/test.html</a> -> <a href="http://yoursite.com/new_dir/dir1/test.html" target="_blank">http://yoursite.com/new_dir/dir1/test.html</a><br/>Tip: 使用用户目录时Redirect不能转向的解决方法<br/>当你使用Apache默认的用户目录，如 <a href="http://mysite.com/~windix" target="_blank">http://mysite.com/~windix</a>，当你想转向 <a href="http://mysite.com/~windix/jump" target="_blank">http://mysite.com/~windix/jump</a>时，你会发现下面这个Redirect不工作:<br/>Redirect /jump <a href="http://www.google.com" target="_blank">http://www.google.com</a><br/>正确的方法是改成<br/>Redirect /~windix/jump <a href="http://www.google.com" target="_blank">http://www.google.com</a><br/>(source: .htaccess Redirect in “Sites” not redirecting: why?<br/>)<br/><br/>10. Prevent viewing of .htaccess file 防止.htaccess文件被查看<br/>order allow,deny<br/>deny from all<br/><br/>11. Adding MIME Types 添加 MIME 类型<br/>AddType application/x-shockwave-flash swf<br/>Tips: 设置类型为 application/octet-stream 将提示下载<br/><br/>12. Preventing hot linking of images and other file types 防盗链<br/>需要mod_rewrite模块<br/>RewriteEngine on<br/>RewriteCond %{HTTP_REFERER} !^$<br/>RewriteCond %{HTTP_REFERER} !^<a href="http://(www/&#92;.)?mydomain.com/." target="_blank">http://(www/&#92;.)?mydomain.com/.</a>*$ [NC]<br/>RewriteRule &#92;.(gif&#124;jpg&#124;js&#124;css)$ - [F]<br/>解析:<br/>若 HTTP_REFERER 非空 (来源为其他站点，非直接连接) 并且<br/>若 HTTP_REFERER 非(<a href="http://www.)mydomain.com" target="_blank">www.)mydomain.com</a>开头(忽略大小写[NC]) (来源非本站)<br/>对于所有含有 .gif/.jpg/.js/.css 结尾的文件给出 403 Forbidden 错误[F]<br/>也可指定响应，如下例显示替换图片<br/>RewriteRule &#92;.(gif&#124;jpg)$<br/>[R,L]<br/>[R] - 转向(Redirect)<br/>[L] - 连接(Link)<br/><br/>13. Preventing Directory Listing 防止目录列表时显示<br/>IndexIgnore *<br/>IndexIgnore *.jpg *.gif<br/>Tips:<br/>允许目录列表显示: Options +Indexes<br/>禁止目录列表显示: Options -Indexes<br/>显示提示信息: 页首 文件HEADER, 页尾 文件README <br/><br/><br/>Tags - <a href="tag.php?tag=.htaccess" rel="tag">.htaccess</a>
]]>
</description>
</item><item>
<link>http://blog.sust.net.ru/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] .htaccess 学习笔记]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://blog.sust.net.ru/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>