<?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>OurApache &#187; htaccess</title>
	<atom:link href="http://ourapache.com/archives/tag/htaccess/feed" rel="self" type="application/rss+xml" />
	<link>http://ourapache.com</link>
	<description>我们致力于一个Apache知识的分享网站</description>
	<lastBuildDate>Tue, 13 Apr 2010 05:18:24 +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>htaccess二级目录重写找不到路径</title>
		<link>http://ourapache.com/archives/316</link>
		<comments>http://ourapache.com/archives/316#comments</comments>
		<pubDate>Tue, 09 Mar 2010 01:36:35 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache初级应用]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[路径]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=316</guid>
		<description><![CDATA[首先申明一下：使用.htaccess文件，会降低httpd服务器的一点性能.h]]></description>
			<content:encoded><![CDATA[<p>首先申明一下：使用.htaccess文件，会降低httpd服务器的一点性能.h<br />
我们一般会把客户的网站放在自己的网站的目录下面，<br />
比如FTP：/home/ftp/www，<br />
有一个网站http://www.example.com，<br />
那么新建一个网站的目录为http://www.example.com/newsite/，<br />
我们这个项目是使用qeephp开发的，使用<a href="http://www.qeephp.com/"><span style="color: #0059b3;">qeephp</span></a>的路由重写功能，在把网站上传到服务器上，<br />
使用了虚拟目录Alias，因为不想看到类似http://www.example.com/newsite/public/这样的路径，<br />
于是外部访问地址是http://www.example.com/newsite,<br />
在我启用了qeephp的rewrite时，一直说找不到路径，/home/ftp/www/newsite/,很奇怪。<br />
仔细阅读htaccess的文档，发现有一个BaseDir参数<br />
在htaccess 中添加</p>
<div class="wp_syntax" style="padding-bottom: 0px;">
<div class="code">
<pre class="ini" style="font-family: monospace;">RewriteEngine on
RewriteBase /twosisters
 
RewriteCond %<span>{</span>REQUEST_FILENAME<span>}</span> -s <span style="font-weight: bold; color: #000066;"><span style="color: #000066;"><span>[</span>OR<span>]</span></span></span>
RewriteCond %<span>{</span>REQUEST_FILENAME<span>}</span> -l <span style="font-weight: bold; color: #000066;"><span style="color: #000066;"><span>[</span>OR<span>]</span></span></span>
RewriteCond %<span>{</span>REQUEST_FILENAME<span>}</span> -d
RewriteRule ^.*$ - <span style="font-weight: bold; color: #000066;"><span style="color: #000066;"><span>[</span>NC,L<span>]</span></span></span>
RewriteRule ^.*$ index.php <span style="font-weight: bold; color: #000066;"><span style="color: #000066;"><span>[</span>NC,L<span>]</span></span></span></pre>
</div>
</div>
<p>问题就解决.<br />
估计把index.php改成绝对路径也没有问题。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年12月12号 -- <a href="http://ourapache.com/archives/310" title=".htaccess的301跳转">.htaccess的301跳转</a></li><li>2009年06月15号 -- <a href="http://ourapache.com/archives/259" title="16个简单实用的.htaccess小贴示">16个简单实用的.htaccess小贴示</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/32" title="htaccess学习笔记">htaccess学习笔记</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/25" title="Apache服务器使用.htaccess实现图片防盗链方法教程">Apache服务器使用.htaccess实现图片防盗链方法教程</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/primary" title="Apache初级应用" rel="tag">Apache初级应用</a>, <a href="http://ourapache.com/archives/tag/htaccess" title="htaccess" rel="tag">htaccess</a>, <a href="http://ourapache.com/archives/tag/%e8%b7%af%e5%be%84" title="路径" rel="tag">路径</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/316/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.htaccess的301跳转</title>
		<link>http://ourapache.com/archives/310</link>
		<comments>http://ourapache.com/archives/310#comments</comments>
		<pubDate>Sat, 12 Dec 2009 15:35:29 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[跳转]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=310</guid>
		<description><![CDATA[.htaccess的301跳转]]></description>
			<content:encoded><![CDATA[<p>server:linux(ubuntu)</p>
<p>add mod_rewrite:1、sudo a2enmod rewrite 2、udo vim /etc/apache2/sites-enabled/000-default</p>
<p>将其中的：</p>
<p>AllowOverride None</p>
<p>修改为：</p>
<p>AllowOverride All</p>
<p>重启生效。</p>
<p>将 htmldata.cn 转换为 www.htmldata.cn</p>
<div class="codecolorer-container text " style="overflow: auto; white-space: nowrap;">
<div class="text codecolorer" style="white-space: nowrap;">
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span><br />
Options +FollowSymlinks<br />
RewriteEngine on<br />
rewritecond %{http_host} ^htmldata.cn [nc]<br />
rewriterule ^(.*)$ http://www.htmldata.cn/$1 [r=<a href="http://ourapache.com/archives/tag/301" class="st_tag internal_tag" rel="tag" title="标签 301 下的日志">301</a>,nc]</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年06月15号 -- <a href="http://ourapache.com/archives/259" title="16个简单实用的.htaccess小贴示">16个简单实用的.htaccess小贴示</a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/97" title="使用apache下的301设置来做域名的更换转移">使用apache下的301设置来做域名的更换转移</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/32" title="htaccess学习笔记">htaccess学习笔记</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/25" title="Apache服务器使用.htaccess实现图片防盗链方法教程">Apache服务器使用.htaccess实现图片防盗链方法教程</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/tag/301" title="301" rel="tag">301</a>, <a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/htaccess" title="htaccess" rel="tag">htaccess</a>, <a href="http://ourapache.com/archives/tag/%e8%b7%b3%e8%bd%ac" title="跳转" rel="tag">跳转</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/310/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>16个简单实用的.htaccess小贴示</title>
		<link>http://ourapache.com/archives/259</link>
		<comments>http://ourapache.com/archives/259#comments</comments>
		<pubDate>Mon, 15 Jun 2009 10:02:02 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=259</guid>
		<description><![CDATA[.htaccess 文件 (Hypertext Access file) 是Apache Web服务器的一个非常强大的配置文件，对于这个文件，Apache有一堆参数可以让你配置出几乎随心所欲的功能。.htaccess 配置文件坚持了Unix的一个文化——使用一个ASCII 的纯文本文件来配置你的网站的访问策略。

这篇文章包括了16个非常有用的小技巧。另外，因为.htaccess 是一个相当强大的配置文件，所以，一个轻微的语法错误会造成你整个网站的故障，所以，在你修改或是替换原有的文件时，一定要备份旧的文件，以便出现问题的时候可以方便的恢复。]]></description>
			<content:encoded><![CDATA[<p>.<a href="http://ourapache.com/archives/tag/htaccess" class="st_tag internal_tag" rel="tag" title="标签 htaccess 下的日志">htaccess</a> 文件 (Hypertext Access file) 是Apache Web服务器的一个非常强大的配置文件，对于这个文件，Apache有一堆参数可以让你配置出几乎随心所欲的功能。.<a href="http://ourapache.com/archives/tag/htaccess" class="st_tag internal_tag" rel="tag" title="标签 htaccess 下的日志">htaccess</a> 配置文件坚持了Unix的一个文化——使用一个ASCII 的纯文本文件来配置你的网站的访问策略。</p>
<p>这篇文章包括了16个非常有用的小技巧。另外，因为.htaccess 是一个相当强大的配置文件，所以，一个轻微的语法错误会造成你整个网站的故障，所以，在你修改或是替换原有的文件时，一定要备份旧的文件，以便出现问题的时候可以方便的恢复。</p>
<p><strong>1. 使用.htaccess 创建自定义的出错页面。对于Linux Apache来说这是一项极其简单的事情。使用下面的.htaccess语法你可以轻松的完成这一功能。（把.htaccess放在你的网站根目录下）</strong></p>
<blockquote><p>ErrorDocument 401 /error/401.php<br />
ErrorDocument 403 /error/403.php<br />
ErrorDocument 404 /error/404.php<br />
ErrorDocument 500 /error/500.php</p></blockquote>
<p><strong>2. 设置网站的时区</strong></p>
<blockquote><p>SetEnv TZ America/Houston</p></blockquote>
<p><strong>3. 阻止IP列表</strong><br />
有些时候，你需要以IP地址的方式阻止一些访问。无论是对于一个IP地址还是一个网段，这都是一件非常简单的事情，如下所示：</p>
<blockquote><p>allow from all<br />
deny from 145.186.14.122<br />
deny from 124.15</p></blockquote>
<p>Apache对于被拒绝的IP会返回403错误。</p>
<p><strong>4. 把一些老的链接转到新的链接上——搜索引擎优化SEO</strong></p>
<blockquote><p>Redirect <a href="http://ourapache.com/archives/tag/301" class="st_tag internal_tag" rel="tag" title="标签 301 下的日志">301</a> /d/file.html http://www.htaccesselite.com/r/file.html</p></blockquote>
<p><strong>5. 为服务器管理员设置电子邮件。</strong></p>
<blockquote><p>ServerSignature EMail<br />
SetEnv SERVER_ADMIN default@domain.com</p></blockquote>
<p><strong>6. 使用.htaccess 访止盗链。如果你网站上的一个图片被别的N多的网站引用了，那么，这很有可能会导致你服务器的性能下降，使用下面的代码可以保护某些热门的链接不被过多的引用。</strong></p>
<blockquote><p>Options +FollowSymlinks<br />
# Protect Hotlinking<br />
RewriteEngine On<br />
RewriteCond %{HTTP_REFERER} !^$<br />
RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]<br />
RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/hotlink_f_o.png [nc]</p></blockquote>
<p><strong>7. 阻止 User Agent 的所有请求</strong></p>
<blockquote><p>## .htaccess Code :: BEGIN<br />
## Block Bad Bots by user-Agent<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]</p>
<p>Order Allow,Deny<br />
Allow from all<br />
Deny from env=bad_bot</p>
<p>## .htaccess Code :: END</p></blockquote>
<p><strong>8. 把某些特殊的IP地址的请求重定向到别的站点</strong></p>
<blockquote><p>ErrorDocument 403 http://www.youdomain.com<br />
Order deny,allow<br />
Deny from all<br />
Allow from ip<br />
Allow from ip</p></blockquote>
<p><strong>9. 直接找开文件而不是下载 – 通常，我们打开网上文件的时候总是会出现一个对话框问我们是下载还是直接打开，使用下面的设置就不会出现这个问题了，直接打开</strong>。</p>
<blockquote><p>AddType application/octet-stream .pdf<br />
AddType application/octet-stream .zip<br />
AddType application/octet-stream .mov</p></blockquote>
<p><strong>10. 修改文件类型 – 下面的示例可以让任何的文件都成为PHP那么被服务器解释。比如：myphp, cgi，phtml等。</strong></p>
<blockquote><p>ForceType application/x-httpd-php<br />
SetHandler application/x-httpd-php</p></blockquote>
<p><strong>11. 阻止存取.htaccess 文件</strong></p>
<blockquote><p># secure htaccess file<br />
order allow,deny<br />
deny from all</p></blockquote>
<p><strong>12. 保护服务器上的文件被存取</strong></p>
<blockquote><p># prevent access of a certain file order allow,deny<br />
deny from all</p></blockquote>
<p><strong>13. 阻止目录浏览</strong></p>
<blockquote><p># disable directory browsing<br />
Options All -Indexes</p></blockquote>
<p><strong>14. 设置默认主页</strong></p>
<blockquote><p># serve alternate default index page<br />
DirectoryIndex about.html</p></blockquote>
<p><strong>15. 口令认证 – 你可以创建一个文件用于认证。下面是一个示例：</strong></p>
<blockquote><p># to protect a file</p>
<p>AuthType Basic<br />
AuthName “Prompt”<br />
AuthUserFile /home/path/.htpasswd<br />
Require valid-user</p>
<p># password-protect a directory<br />
resides<br />
AuthType basic<br />
AuthName “This directory is protected”<br />
AuthUserFile /home/path/.htpasswd<br />
AuthGroupFile /dev/null<br />
Require valid-user</p></blockquote>
<p><strong>16. 把老的域名转像新的域名</strong></p>
<blockquote><p># redirect from old domain to new domain<br />
RewriteEngine On<br />
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]</p></blockquote>
<p>标签: <a rel="external" href="http://www.wopus.org/tag/htaccess"><span style="color: #004499;">.htaccess</span></a></p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/310" title=".htaccess的301跳转">.htaccess的301跳转</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/32" title="htaccess学习笔记">htaccess学习笔记</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/25" title="Apache服务器使用.htaccess实现图片防盗链方法教程">Apache服务器使用.htaccess实现图片防盗链方法教程</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/htaccess" title="htaccess" rel="tag">htaccess</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/259/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>htaccess学习笔记</title>
		<link>http://ourapache.com/archives/32</link>
		<comments>http://ourapache.com/archives/32#comments</comments>
		<pubDate>Tue, 06 Jan 2009 06:23:25 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=32</guid>
		<description><![CDATA[.htaccess可以做大量范围的事情，包括：文件夹密码保护、用户自动重新指向、自定义错误页面、变更你的文件扩展名、屏蔽特定的用户IP地址、只允许特定的IP地址、停止目录表以及使用其他文件作为index文件，等等......]]></description>
			<content:encoded><![CDATA[<p>.htaccess可以做大量范围的事情，包括：文件夹密码保护、用户自动重新指向、自定义错误页面、变更你的文件扩展名、屏蔽特定的用户IP地址、只允许特定的IP地址、停止目录表以及使用其他文件作为index文件，等等&#8230;&#8230;</p>
<p>1. Introduction 介绍<br />
文件名 .<a href="http://ourapache.com/archives/tag/htaccess" class="st_tag internal_tag" rel="tag" title="标签 htaccess 下的日志">htaccess</a> 属性 644 (RW-R–R–)<br />
htaccess会影响它所在目录下的所有子目录<br />
注意大多数内容都要求保持在一行之内，不要换行，否则会引起错误</p>
<p>2. Error Documents 错误文档<br />
Official document: ErrorDocument Directive<br />
ErrorDocument code document<br />
例子<br />
ErrorDocument 400 /errors/badrequest.html<br />
ErrorDocument 404 <a rel="external" href="http://yoursite/errors/notfound.html" target="_blank">http://yoursite/errors/notfound.html</a><br />
ErrorDocument 401 “Authorization Required”<br />
(注意之后内容如果出现的双引号需要转义为 ”)<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 />
<a href="http://ourapache.com/archives/tag/301" class="st_tag internal_tag" rel="tag" title="标签 301 下的日志">301</a> 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</p>
<p>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</p>
<p>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</p>
<p>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</p>
<p>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.com [NC]<br />
RewriteRule .* &#8211; [F]<br />
例2. 阻止多个referrer: badsite1.com, badsite2.com<br />
RewriteEngine on<br />
# Options +FollowSymlinks<br />
RewriteCond %{HTTP_REFERER} badsite1.com [NC,OR]<br />
RewriteCond %{HTTP_REFERER} badsite2.com<br />
RewriteRule .* &#8211; [F]<br />
[NC] &#8211; 大小写不敏感(Case-insensite)<br />
[F] &#8211; 403 Forbidden<br />
注意以上代码注释掉了”Options +FollowSymlinks”这个语句。如果服务器未在 httpd.conf 的 段落设置 FollowSymLinks, 则需要加上这句，否则会得到”500 Internal Server error”错误。</p>
<p>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 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 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 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 Stripper [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Image Sucker [OR]<br />
RewriteCond %{HTTP_USER_AGENT} Indy Library [NC,OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Internet Ninja [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^JOC Web Spider [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Mass Downloader [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^MIDown tool [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Mister 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 Vampire [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Offline Explorer [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Offline Navigator [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Papa 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 Pro [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Web Image Collector [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Web 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 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 eXtractor [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Website 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 WebSpider [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Zeus<br />
RewriteRule ^.* &#8211; [F,L]<br />
[F] &#8211; 403 Forbidden<br />
[L] &#8211; 连接(Link)</p>
<p>8. Change your default directory page 改变缺省目录页面<br />
DirectoryIndex index.html index.php index.cgi index.pl</p>
<p>9. Redirects 转向<br />
单个文件<br />
Redirect /old_dir/old_file.html <a rel="external" 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 rel="external" href="http://yoursite.com/new_dir" target="_blank">http://yoursite.com/new_dir</a><br />
效果: 如同将目录移动位置一样<br />
<a rel="external" href="http://yoursite.com/old_dir" target="_blank">http://yoursite.com/old_dir</a> -&gt; <a rel="external" href="http://yoursite.com/new_dir" target="_blank">http://yoursite.com/new_dir</a><br />
<a rel="external" href="http://yoursite.com/old_dir" target="_blank">http://yoursite.com/old_dir</a>/dir1/test.html -&gt; <a rel="external" href="http://yoursite.com/new_dir" target="_blank">http://yoursite.com/new_dir</a>/dir1/test.html<br />
Tip: 使用用户目录时Redirect不能转向的解决方法<br />
当你使用Apache默认的用户目录，如 <a rel="external" href="http://mysite.com/~windix" target="_blank">http://mysite.com/~windix</a>，当你想转向 <a rel="external" href="http://mysite.com/~windix/jump" target="_blank">http://mysite.com/~windix/jump</a>时，你会发现下面这个Redirect不工作:<br />
Redirect /jump <a rel="external" href="http://www.google.com/" target="_blank">http://www.google.com</a><br />
正确的方法是改成<br />
Redirect /~windix/jump <a rel="external" href="http://www.google.com/" target="_blank">http://www.google.com</a><br />
(source: .htaccess Redirect in “Sites” not redirecting: why?<br />
)</p>
<p>10. Prevent viewing of .htaccess file 防止.htaccess文件被查看<br />
order allow,deny<br />
deny from all</p>
<p>11. Adding MIME Types 添加 MIME 类型<br />
AddType application/x-shockwave-flash swf<br />
Tips: 设置类型为 application/octet-stream 将提示下载</p>
<p>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 rel="external" href="http:///" target="_blank">http://</a>(www/.)?mydomain.com/.*$ [NC]<br />
RewriteRule .(gif|jpg|js|css)$ &#8211; [F]<br />
解析:<br />
若 HTTP_REFERER 非空 (来源为其他站点，非直接连接) 并且<br />
若 HTTP_REFERER 非(www.)mydomain.com开头(忽略大小写[NC]) (来源非本站)<br />
对于所有含有 .gif/.jpg/.js/.css 结尾的文件给出 403 Forbidden 错误[F]<br />
也可指定响应，如下例显示替换图片<br />
RewriteRule .(gif|jpg)$ [R,L]<br />
[R] &#8211; 转向(Redirect)<br />
[L] &#8211; 连接(Link)</p>
<p>13. Preventing Directory Listing 防止目录列表时显示<br />
IndexIgnore *<br />
IndexIgnore *.jpg *.gif<br />
Tips:<br />
允许目录列表显示: Options +Indexes<br />
禁止目录列表显示: Options -Indexes<br />
显示提示信息: 页首 文件HEADER, 页尾 文件README</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/310" title=".htaccess的301跳转">.htaccess的301跳转</a></li><li>2009年06月15号 -- <a href="http://ourapache.com/archives/259" title="16个简单实用的.htaccess小贴示">16个简单实用的.htaccess小贴示</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/25" title="Apache服务器使用.htaccess实现图片防盗链方法教程">Apache服务器使用.htaccess实现图片防盗链方法教程</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/htaccess" title="htaccess" rel="tag">htaccess</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/32/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache服务器使用.htaccess实现图片防盗链方法教程</title>
		<link>http://ourapache.com/archives/25</link>
		<comments>http://ourapache.com/archives/25#comments</comments>
		<pubDate>Tue, 06 Jan 2009 06:06:29 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache初级应用]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[盗链]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=25</guid>
		<description><![CDATA[独立建博的用户经常面对的一个问题就是服务器的流量问题，而站点文件被盗链是其中最为主要的部分。所谓盗链，是指其他网站直接链接我们网站上的文 件，一般来说，盗链的对象大多为很耗带宽的大体积文件，如图片、视频等。这样造成的后果主要有：增加了服务器的流量负担，影响我们网站的访问速度。

如果你用的是Apache服务器，那么使用.htaccess文件就可以很方便的进行设置，从而防止其他站点的用户盗链我们站点的文件。]]></description>
			<content:encoded><![CDATA[<p>独立建博的用户经常面对的一个问题就是服务器的流量问题，而站点文件被盗链是其中最为主要的部分。所谓盗链，是指其他网站直接链接我们网站上的文 件，一般来说，盗链的对象大多为很耗带宽的大体积文件，如图片、视频等。这样造成的后果主要有：增加了服务器的流量负担，影响我们网站的访问速度。</p>
<p>如果你用的是Apache服务器，那么使用.htaccess文件就可以很方便的进行设置，从而防止其他站点的用户盗链我们站点的文件。</p>
<p><strong>Apache中的.htaccess文件</strong></p>
<p>.htaccess文件是Apache中相当重要的配置文件，其格式为纯文本，它提供了针对目录改变配置的方法，通过在一个特定的文档目录中放置一个包含一个或多个指令的文件，以作用于此目录及其所有子目录。</p>
<p>通过.htaccess文件，可以实现简单地很多在IIS中很繁琐甚至无法实现的功能，如密码保护、禁止显示目录列表、阻止/允许特定的IP地址、实现网址的301 重定向等等。</p>
<p>正 如上面所说，.htaccess文件将影响其所在的目录及其子目录，因此，如果我们要保护的内容（此处以防止图片盗链为例，即图片）位于网站内多个目录 下，可以考虑将其放在根目录下；而如果图片有单独的子目录如“/images/”，则只需将其放置在该目录下（当然也可以放到根目录中）。</p>
<p>需 要注意的是，如果通过FTP方式将创建好的.htaccess上传到服务器上，传输模式应为ASCII而非Binary。上传到服务器后，应将其属性通过 CHMOD修改为644 或“RW-R–R–”，这样，可以保证服务器能够使用同时无法通过浏览器修改，当然，.htaccess的可读属性也存在一定的风险：攻击者可通过它找出 您要保护的对象或认证文件位置——解决办法是将认证文件.htpasswd放到网站根目录之外，这样，便无法通过网络找到它了。</p>
<p><strong>使用.htaccess禁止盗链</strong></p>
<p>通过.htaccess来防止网站的图片、压缩文件、或视频等非Html文件被盗链的方法相当简单，通过在该文件中加入几句命令即可保护我们宝贵的带宽。例如本站的设置如下：</p>
<blockquote><p>RewriteEngine on</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !^$ [NC]</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !webeta.cn [NC]</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !ikuaizi.com [NC]</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !xianguo.com [NC]</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !google.com [NC]</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !bloglines.com [NC]</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !feedburner.com [NC]</p></blockquote>
<blockquote><p>RewriteCond %{HTTP_REFERER} !feedsky.com [NC]</p></blockquote>
<blockquote><p>RewriteRule .*.(gif|jpg)$ <a href="http://webeta.cn/no.png" target="_blank"><span style="text-decoration: underline;"><span style="color: #0000ff;">http://webeta.cn/no.png</span></span></a> [R,NC,L]</p></blockquote>
<p>简单的解释一下上述语句：</p>
<p><strong>1、RewriteCond %{HTTP_REFERER} !^$ [NC]</strong></p>
<p>允许空“HTTP_REFERER”的访问，即允许用户在浏览器地址栏中直接输入图片地址时图片文件的显示。一般而言，这是可选的，不过，建议这么设置，如果强迫必须具有“HTTP_REFERER”才能访问，可能会带来某些问题，比如说在用户通过代理服务器访问时。</p>
<p><strong>2、RewriteCond %{HTTP_REFERER} !webeta.cn [NC]</strong></p>
<p>设置允许访问的HTTP来源，包括我们的站点自身、Google、Baidu、Bloglines、Feedburner等。</p>
<p><strong>3、RewriteRule .*.(gif|jpg|png)$ </strong><a href="http://webeta.cn/no.png" target="_blank"><strong><span style="text-decoration: underline;"><span style="color: #0000ff;">http://webeta.cn/no.png</span></span></strong></a><strong> [R,NC,L]</strong></p>
<p>定义被盗链时替代的图片，让所有盗链 jpg、gif、png 等文件的网页，显示根目录下的 no.png 文件。注意：替换显示的图片不要放在设置防盗链的目录中，并且该图片文件体积越小越好。当然你也可以不设置替换图片，而是使用下面的语句即可：</p>
<blockquote><p>RewriteRule .*.(gif|jpg|png)$ &#8211; [F]</p></blockquote>
<p><strong>4、说明一下其中的R、NC 和 L</strong></p>
<p>R 就是转向的意思</p>
<p>NC 指的是不区分大小写</p>
<p>L 的作用是指明本次转向到此结束，后续的转向不受先前判断语句的影响</p>
<p><strong>5、防止盗链的文件类型</strong></p>
<p>上例中是 gif、jpg、png，而根据需要，可更改或添加其他文件类型，如rar、mov等，不同文件扩展名间使用“|”分割。</p>
<p>这样的话，就可以基本做到简单的防止被盗链情况的发生，而且可以尽最大可能的减少服务器流量的无畏消耗，当然了，如果你不在意这点流量的话，那么可以不用考虑上述设置啦！</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/310" title=".htaccess的301跳转">.htaccess的301跳转</a></li><li>2009年06月15号 -- <a href="http://ourapache.com/archives/259" title="16个简单实用的.htaccess小贴示">16个简单实用的.htaccess小贴示</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/32" title="htaccess学习笔记">htaccess学习笔记</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/primary" title="Apache初级应用" rel="tag">Apache初级应用</a>, <a href="http://ourapache.com/archives/tag/htaccess" title="htaccess" rel="tag">htaccess</a>, <a href="http://ourapache.com/archives/tag/%e7%9b%97%e9%93%be" title="盗链" rel="tag">盗链</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/25/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apache中.htaccess的功能及写法</title>
		<link>http://ourapache.com/archives/7</link>
		<comments>http://ourapache.com/archives/7#comments</comments>
		<pubDate>Sat, 27 Dec 2008 15:15:58 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=7</guid>
		<description><![CDATA[.htaccess 文件(或者"分布式配置文件"提供了针对目录改变配置的方法，即，在一个特定的文档目录中放置一个包含一个或多个指令的文件，以作用于此目录及其所有子目录。作为用户，所能使用的命令受到限制。管理员可以通过Apache的AllowOverride指令来设置。]]></description>
			<content:encoded><![CDATA[<p>- .<a href="http://ourapache.com/archives/tag/htaccess" class="st_tag internal_tag" rel="tag" title="标签 htaccess 下的日志">htaccess</a> 文件(或者”分布式配置文件”提供了针对目录改变配置的方法，即，在一个特定的文档目录中放置一个包含一个或多个指令的文件，以作用于此目录及其所有子目录。作为用户，所能使用的命令受到限制。管理员可以通过Apache的AllowOverride指令来设置。</p>
<p>- 子目录中的指令会覆盖更高级目录或者主服务器配置文件中的指令。</p>
<p>- .htaccess必须以ASCII模式上传，最好将其权限设置为644。</p>
<p><strong>错误文档的定位 </strong></p>
<p>常用的客户端请求错误返回代码：<br />
401 Authorization Required<br />
403 Forbidden<br />
404 Not Found<br />
405 Method Not Allowed<br />
408 Request Timed Out<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 />
常见的服务器错误返回代码：<br />
500 Internal Server Error</p>
<p>用户可以利用.htaccess指定自己事先制作好的错误提醒页面。一般情况下，人们可以专门设立一个目录，例如errors放置这些页面。然后再.htaccess中，加入如下的指令：</p>
<div>
<div>ErrorDocument 404 /errors/notfound.html<br />
ErrorDocument 500 /errors/internalerror.html</div>
</div>
<p>一条指令一行。上述第一条指令的意思是对于404，也就是没有找到所需要的文档的时候得显示页面为/errors目录下的notfound.html页面。不难看出语法格式为：</p>
<div>
<div>ErrorDocument 错误代码 /目录名/文件名.扩展名</div>
</div>
<p>如果所需要提示的信息很少的话，不必专门制作页面，直接在指令中使用HTML号了，例如下面这个例子：</p>
<div>
<div>ErrorDocument 401 “&lt;body bgcolor=#ffffff&gt;&lt;h1&gt;你没有权限访问该页面，请放弃！&lt;/h1&gt;&lt;/body&gt;”</div>
</div>
<p><strong>文档访问的密码保护</strong></p>
<p>要利用.htaccess对某个目录下的文档设定访问用户和对应的密码，首先要做的是生成一个.htpasswd的文本文档，例如：</p>
<div>
<div>zheng:y4E7Ep8e7EYV</div>
</div>
<p>这里密码经过加密，用户可以自己找些工具将密码加密成.htaccess支持的编码。该文档最好不要放在www目录下，建议放在www根目录文档之外，这样更为安全些。</p>
<p>有了授权用户文档，可以在.htaccess中加入如下指令了：</p>
<div>
<div>AuthUserFile .htpasswd的服务器目录<br />
AuthGroupFile /dev/null （需要授权访问的目录）<br />
AuthName EnterPassword<br />
AuthType Basic （授权类型）</p>
<p>require user wsabstract （允许访问的用户，如果希望表中所有用户都允许，可以使用 require valid-user）</p></div>
</div>
<p>注，括号部分为学习时候自己添加的注释</p>
<p><strong>拒绝来自某个IP的访问 </strong></p>
<p>如果我不想某个政府部门访问到我的站点的内容，那可以通过.htaccess中加入该部门的IP而将它们拒绝在外。</p>
<p>例如：</p>
<div>
<div>order allow,deny<br />
deny from 210.21.112.43<br />
deny from 219.146.95<br />
allow from all</div>
</div>
<p>第二行拒绝某个IP，第三行拒绝某个IP段，也就是219.146.95.0~219.146.95.255</p>
<p>想要拒绝所有人？用deny from all好了。不止用IP，也可以用域名来设定。</p>
<p><strong>保护.htaccess文档 </strong></p>
<p>在使用.htaccess来设置目录的密码保护时，它包含了密码文件的路径。从安全考虑，有必要把.htaccess也保护起来，不让别人看到其中的内容。虽然可以用其他方式做到这点，比如文档的权限。不过，.htaccess本身也能做到，只需加入如下的指令：</p>
<div>
<div>&lt;Files .htaccess&gt;<br />
order allow,deny<br />
deny from all<br />
&lt;/Files&gt;</div>
</div>
<p><strong>URL转向 </strong></p>
<p>我们可能对网站进行重新规划，将文档进行了迁移，或者更改了目录。这时候，来自搜索引擎或者其他网站链接过来的访问就可能出错。这种情况下，可以通过如下指令来完成旧的URL自动转向到新的地址：</p>
<div>
<div>Redirect /旧目录/旧文档名 新文档的地址</div>
</div>
<p>或者整个目录的转向：</p>
<div>
<div>Redirect 旧目录 新目录</div>
</div>
<p><strong>改变缺省的首页文件 </strong></p>
<p>一般情况下缺省的首页文件名有default、index等。不过，有些时候目录中没有缺省文件，而是某个特定的文件名，比如在pmwiki中是pmwiki.php。这种情况下，要用户记住文件名来访问很麻烦。在.htaccess中可以轻易的设置新的缺省文件名：</p>
<div>
<div>DirectoryIndex 新的缺省文件名</div>
</div>
<p>也可以列出多个，顺序表明它们之间的优先级别，例如：</p>
<div>
<div>DirectoryIndex filename.html index.cgi index.pl default.htm</div>
</div>
<p><strong>防止盗链</strong></p>
<p>如果不喜欢别人在他们的网页上连接自己的图片、文档的话，也可以通过htaccess的指令来做到。</p>
<p>所需要的指令如下：</p>
<div>
<div>RewriteEngine on<br />
RewriteCond % !^$<br />
RewriteCond % !^http://(www.)?phpv.net/.*$ [NC]<br />
RewriteRule .(gif|jpg)$ &#8211; [F]</div>
</div>
<p>如果觉得让别人的页面开个天窗不好看，那可以用一张图片来代替：</p>
<div>
<div>RewriteEngine on<br />
RewriteCond % !^$<br />
RewriteCond % !^http://(www.)?mydomain.com/.*$ [NC]<br />
RewriteRule .(gif|jpg)$ http://www.phpv.net/img_PageNotFound.gif [R,L]</div>
</div>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/318" title="Apache2中俩种设置PHP的异同">Apache2中俩种设置PHP的异同</a></li><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/310" title=".htaccess的301跳转">.htaccess的301跳转</a></li><li>2009年06月15号 -- <a href="http://ourapache.com/archives/259" title="16个简单实用的.htaccess小贴示">16个简单实用的.htaccess小贴示</a></li><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/123" title="Apache高级配置中文详解">Apache高级配置中文详解</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/66" title="Apache配置文件(httpd.conf)中文说明">Apache配置文件(httpd.conf)中文说明</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/32" title="htaccess学习笔记">htaccess学习笔记</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/25" title="Apache服务器使用.htaccess实现图片防盗链方法教程">Apache服务器使用.htaccess实现图片防盗链方法教程</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/9" title="apache禁止使用IP访问的实现方法">apache禁止使用IP访问的实现方法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/htaccess" title="htaccess" rel="tag">htaccess</a>, <a href="http://ourapache.com/archives/tag/%e9%85%8d%e7%bd%ae" title="配置" rel="tag">配置</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/7/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

