<?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; .htaccess</title>
	<atom:link href="http://www.litanwei.com/tag/htaccess/feed" rel="self" type="application/rss+xml" />
	<link>http://www.litanwei.com</link>
	<description>讨论和学习互联网产品策划、用户体验、网站架构、网站运营、网络营销以及相关内容。</description>
	<lastBuildDate>Wed, 08 Feb 2012 02:59:08 +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 提高 WordPress 的安全性和可用性</title>
		<link>http://www.litanwei.com/htaccess/381</link>
		<comments>http://www.litanwei.com/htaccess/381#comments</comments>
		<pubDate>Mon, 10 May 2010 03:37:11 +0000</pubDate>
		<dc:creator>李谭伟</dc:creator>
				<category><![CDATA[网摘]]></category>
		<category><![CDATA[.htaccess]]></category>

		<guid isPermaLink="false">http://www.litanwei.com/?p=381</guid>
		<description><![CDATA[.htaccess 是一个特殊的文件，它能改变你服务器上的设置和允许你做很多不同的东东，如它能定制化 404 错误页面。.htaccess 其实并不难，我们可以把它认为它只是由一些简单命令或者用法说明组成的文本文件，不过它却能极大的提高站点的安全性。

1. 保护 .htaccess 自身的安全性

阻止用户通过读取和写入 .htaceess 来更改服务器安全性的设置。

<span class="readmore"><a href="http://www.litanwei.com/htaccess/381" title="使用 .htaccess 提高 WordPress 的安全性和可用性">阅读全文——共2200字</a></span>]]></description>
			<content:encoded><![CDATA[<p><span class='wp_keywordlink_affiliate'><a href="http://www.litanwei.com/tag/htaccess" title="查看 .htaccess 中的全部文章" target="_blank">.htaccess</a></span> 是一个特殊的文件，它能改变你服务器上的设置和允许你做很多不同的东东，如它能定制化 404 错误页面。<span class='wp_keywordlink_affiliate'><a href="http://www.litanwei.com/tag/htaccess" title="查看 .htaccess 中的全部文章" target="_blank">.htaccess</a></span> 其实并不难，我们可以把它认为它只是由一些简单命令或者用法说明组成的文本文件，不过它却能极大的提高站点的安全性。<span id="more-381"></span></p>
<h2>1. 保护 <span class='wp_keywordlink_affiliate'><a href="http://www.litanwei.com/tag/htaccess" title="查看 .htaccess 中的全部文章" target="_blank">.htaccess</a></span> 自身的安全性</h2>
<p>阻止用户通过读取和写入 .htaceess 来更改服务器安全性的设置。</p>
<pre>&lt;files .htaccess&gt;
order allow,deny
deny from all
&lt;/files&gt;</pre>
<h2>2. 隐藏服务器的数字签名</h2>
<p>隐藏服务器的数字签名之后，入侵者将很难有机会找到安全漏洞，因为他们不知道背后的服务器是什么。</p>
<pre>ServerSignature Off</pre>
<h2>3. 限制上传文件的大小</h2>
<p>这个能够帮助阻止 DoS 攻击（用户通过上传巨大的文件来冲垮服务器）并且能够节约带宽。</p>
<pre>LimitRequestBody 10240000
# limit file uploads to 10mb</pre>
<h2>4. 停止 mod_security 过滤器</h2>
<p>这是一个可选的设置并且要小心处理。这些指令告诉服务器不要使用 mod_security 过滤器，因为 mod_security 过滤器不允许用户发表含有这些单词 “curl”，“lynx” 或者 “wget” 等等单词的文章。这个看起来有点琐碎，但是这个让一些站点头痛，因为这些单词几乎那些站点每天都会用到。</p>
<pre>SecFilterInheritance Off</pre>
<h2>5. 保护 wp-config.php 文件</h2>
<p>我们可以通过 .htaccess 文件阻止用户读取和写入 WordPress 的配置文件。这个指令假设 WordPress 是安装在根目录。</p>
<pre>&lt;files wp-config.php&gt;
order allow,deny
deny from all
&lt;/files&gt;</pre>
<h2>6. 自定义错误文档</h2>
<p>这条指令做的更多是站点的可用性而不是安全性。它们指定了一旦服务器错误，哪个页面将被显示，如页面找不到（代码 404） 禁止访问（代码 403）等等。</p>
<pre>ErrorDocument 404 /notfound.php
ErrorDocument 403 /forbidden.php
ErrorDocument 500 /error.php</pre>
<h2>7. 禁止浏览目录</h2>
<p>这将阻止服务器在没有 index 文件（如 index.html，index.php 等等）的情况下显示文件夹目录内容，阻止用户看到文件夹的内容使得更难对网站发动攻击。</p>
<pre># disable directory browsing
Options All -Indexes</pre>
<h2>8. 防止图片盗链</h2>
<p>这个能够阻止其他网站盗链本网站的图片，迫使他们 要么指向整个页面，或者其他存储图像的地方。这个保存了宝贵的带宽并且能够增加流量（虽然只是一点点）。当有人试着直接链接到你的网站来显示图片，下面的代码将会得显示 <code>stealingisbad.gif</code> 这张图片。</p>
<pre>#disable hotlinking of images
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourdomain.com/.*$ [NC]
RewriteRule .(gif|jpg|png)$ http://www.yourdomain.com/stealingisbad.gif [R,L]</pre>
<h2>9. 在你的站点给每个 URL 设置符合规定的或者“标准”的链接</h2>
<p>这能够帮助提高网站的可用性和提高网站在搜索引擎中的排名。总之，它会把来自<code>http://yourdomain.com</code> 的请求重定向到 <code>http://www.yourdomain.com/.</code></p>
<pre># set the canonical url
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]</pre>
<h2>10. 保护博客免受垃圾留言的侵扰</h2>
<p>最后的那条指令将会阻止用户直接从其他网站的留言提交框发表留言，虽然这不是一个可以的防止所有垃圾垃圾留言的方法，但是它确实能够帮助你。</p>
<pre># protect from spam comments
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.*yourdomain.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]</pre>
<p>加入这些指令之后，你应该添加 WordPress 用于管理永久链接的代码。还有很多的指令和很多的方法可以提高网站的可用性和安全性，不过这里所列出的应该占了日常所需的大部分了。当你上传该文件到服务 器上之后，你应该仔细测试直到所有的东西都工作正常。检查下是否受保护的文件还能不能被访问，你依旧允许访问的文件和文件夹能 否还能访问。</p>
<p>一篇很不错的文章，转载保存一下。</p>
<p>原文地址：<a href="http://fairyfish.net/2007/08/01/using-htaccess-to-secure-and-improve-wordpress/">http://fairyfish.net/2007/08/01/using-htaccess-to-secure-and-improve-wordpress/</a></p>
<h2  class="related_post_title">随机推荐阅读：</h2><ul class="related_post"><li><a href="http://www.litanwei.com/nosql/532" title="5款备受关注的开源 NoSQL 数据库介绍">5款备受关注的开源 NoSQL 数据库介绍</a> (0)</li><li><a href="http://www.litanwei.com/geren-zhishi-tixi/595" title="建立个人的知识体系">建立个人的知识体系</a> (0)</li><li><a href="http://www.litanwei.com/yumingqiangzhu/440" title="删除域名抢注实战">删除域名抢注实战</a> (12)</li><li><a href="http://www.litanwei.com/12306-huochepiao/524" title="12306网上订火车票攻略：实用脚本实现半自动化">12306网上订火车票攻略：实用脚本实现半自动化</a> (1)</li><li><a href="http://www.litanwei.com/jiaohu-shejishi-zhuanye/307" title="交互设计师的专业度表现">交互设计师的专业度表现</a> (0)</li><li><a href="http://www.litanwei.com/google-system-administrator/446" title="Google的系统工程师(SA)如何工作">Google的系统工程师(SA)如何工作</a> (2)</li><li><a href="http://www.litanwei.com/tosae/502" title="博客搬家到新浪SAE服务器，暂时使用二级域名访问">博客搬家到新浪SAE服务器，暂时使用二级域名访问</a> (13)</li><li><a href="http://www.litanwei.com/chanping-sheji-wendang/337" title=" 产品设计中为什么需要撰写文档？"> 产品设计中为什么需要撰写文档？</a> (0)</li><li><a href="http://www.litanwei.com/itjianghu-shequmeit/80" title="IT江湖聚会：社区媒体">IT江湖聚会：社区媒体</a> (0)</li><li><a href="http://www.litanwei.com/mianjiekaifa/567" title="敏捷开发思想谈">敏捷开发思想谈</a> (0)</li></ul><h3>Related Posts</h3><ul><li>0</li></ul><h3>Recent Comments</h3><ul><li><a class="commentor" href="http://www.66kaka.com/" >出售银行卡</a> : <a class="comment_content" href="http://www.litanwei.com/htaccess/381#comment-198" title="View the entire comment by 出售银行卡" >这篇文章需要顶，确实学习不少</a></li>
<li><a class="commentor" href="http://www.seomimic.com" >成都SEO</a> : <a class="comment_content" href="http://www.litanwei.com/htaccess/381#comment-197" title="View the entire comment by 成都SEO" >敢不敢不用nofollow属性</a></li>
<li><a class="commentor" href="http://www.beijingjiazhuang.com" >杨涛</a> : <a class="comment_content" href="http://www.litanwei.com/htaccess/381#comment-196" title="View the entire comment by 杨涛" >领教了！不过更新速度再快些，我们等着呢 /呲牙</a></li>
<li><a class="commentor" href="http://www.iiscan.com" >亿思网站安全检测</a> : <a class="comment_content" href="http://www.litanwei.com/htaccess/381#comment-195" title="View the entire comment by 亿思网站安全检测" >“亿思网站安全检测http://www.iiscan.com”　
嗯，支持，继续关注 !!!</a></li>
<li><a class="commentor" href="http://www.luosiming.com" >网络推广</a> : <a class="comment_content" href="http://www.litanwei.com/htaccess/381#comment-194" title="View the entire comment by 网络推广" >分析不错 值得学习 网络推广大使到此一游 望回踩！(*^__^*) 嘻嘻……
多嘴一句，换链接吗ww...</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.litanwei.com/htaccess/381/feed</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
	</channel>
</rss>

