forked from soulteary/forever-coolshell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,909 changed files
with
322,663 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
<!DOCTYPE html><!--[if IE 8]> | ||
<html id="ie8" dir="ltr" lang="zh-CN" | ||
prefix="og: https://ogp.me/ns#" > | ||
<![endif]--><!--[if !(IE 8) ]><!--><html dir="ltr" lang="zh-CN" prefix="og: https://ogp.me/ns#"><!--<![endif]--><head><meta charset="UTF-8"/><title>16个简单实用的.htaccess小贴示 | 酷 壳 - CoolShell</title><link rel="stylesheet" type="text/css" href="/assets/all.min.css"/><link rel="shortcut icon" href="/assets/favicon.png"/></head> | ||
<body class="post-template-default single single-post postid-1035 single-format-standard group-blog"> | ||
|
||
<div id="page" class="hfeed site"> | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
|
||
</div> | ||
</div> | ||
<div id="content" class="site-content"> | ||
<div class="container"> | ||
<div class="row"> | ||
<div id="primary" class="content-area col-md-12" style="margin-top: 40px;"> | ||
<main id="main" role="main"> | ||
<article id="post-1035" class="post-content post-1035 post type-post status-publish format-standard hentry category-webdev category-misc tag-htaccess tag-apache"> | ||
<header class="entry-header"> | ||
<span class="screen-reader-text">16个简单实用的.htaccess小贴示</span> | ||
<h1 class="entry-title">16个简单实用的.htaccess小贴示</h1> | ||
<div class="entry-meta"> | ||
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/1035.html" title="12:27" rel="bookmark"><time class="entry-date" datetime="2009-06-14T12:27:09+08:00" pubdate="">2009年06月14日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i> | ||
<span class="author vcard"><a class="url fn n" href="/articles/author/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/1035.html#comments" class="comments-link">6 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 6,210 人阅读</h5> | ||
</div> | ||
</header> | ||
<div class="entry-content"> | ||
<p>.htaccess 文件 (Hypertext Access file) 是Apache Web服务器的一个非常强大的配置文件,对于这个文件,Apache有一堆参数可以让你配置出几乎随心所欲的功能。.htaccess 配置文件坚持了Unix的一个文化——使用一个ASCII 的纯文本文件来配置你的网站的访问策略。</p> | ||
<p>这篇文章包括了16个非常有用的小技巧。另外,因为.htaccess 是一个相当强大的配置文件,所以,一个轻微的语法错误会造成你整个网站的故障,所以,在你修改或是替换原有的文件时,一定要备份旧的文件,以便出现问题的时候可以方便的恢复。</p> | ||
<p><strong>1. 使用.htaccess 创建自定义的出错页面。</strong>对于Linux Apache来说这是一项极其简单的事情。使用下面的.htaccess语法你可以轻松的完成这一功能。(把.htaccess放在你的网站根目录下)</p> | ||
<p><span style="COLOR: #ff6600">ErrorDocument 401 /error/401.php<br/> | ||
ErrorDocument 403 /error/403.php<br/> | ||
ErrorDocument 404 /error/404.php<br/> | ||
ErrorDocument 500 /error/500.php</span></p> | ||
<p><span style="COLOR: #ff6600"><span id="more-1035"></span></span></p> | ||
<p><strong>2. 设置网站的时区</strong></p> | ||
<p><span style="COLOR: #ff6600">SetEnv TZ America/Houston</span></p> | ||
<p><strong>3. 阻止IP列表</strong><br/> | ||
有些时候,你需要以IP地址的方式阻止一些访问。无论是对于一个IP地址还是一个网段,这都是一件非常简单的事情,如下所示:</p> | ||
<p><span style="COLOR: #ff6600">allow from all<br/> | ||
deny from 145.186.14.122<br/> | ||
deny from 124.15</span></p> | ||
<p>Apache对于被拒绝的IP会返回403错误。</p> | ||
<p><strong>4. 把一些老的链接转到新的链接上——搜索引擎优化SEO </strong></p> | ||
<p><span style="COLOR: #ff6600">Redirect 301 /d/file.html </span><a href="http://www.htaccesselite.com/r/file.html"><span style="COLOR: #ff6600">http://www.htaccesselite.com/r/file.html</span></a></p> | ||
<p><strong>5. 为服务器管理员设置电子邮件。</strong></p> | ||
<p><span style="COLOR: #ff6600">ServerSignature EMail<br/> | ||
SetEnv SERVER_ADMIN </span><a href="/cdn-cgi/l/email-protection#2b4f4e4d4a5e475f6b4f44464a424505484446"><span style="COLOR: #ff6600"><span class="__cf_email__" data-cfemail="bcd8d9daddc9d0c8fcd8d3d1ddd5d292dfd3d1">[email protected]</span></span></a></p> | ||
<p><strong>6. 使用.htaccess 访止盗链。</strong>如果你网站上的一个图片被别的N多的网站引用了,那么,这很有可能会导致你服务器的性能下降,使用下面的代码可以保护某些热门的链接不被过多的引用。</p> | ||
<p><span style="COLOR: #ff6600">Options +FollowSymlinks<br/> | ||
# Protect Hotlinking<br/> | ||
RewriteEngine On<br/> | ||
RewriteCond %{HTTP_REFERER} !^$<br/> | ||
RewriteCond %{HTTP_REFERER} !^http://(</span><a href="http://www.%29/?domainname.com/"><span style="COLOR: #ff6600">www.)?domainname.com/</span></a><span style="COLOR: #ff6600"> [nc]<br/> | ||
RewriteRule .*.(gif|jpg|png)$ </span><a href="http://domainname.com/img/hotlink_f_o.png"><span style="COLOR: #ff6600">http://domainname.com/img/hotlink_f_o.png</span></a><span style="COLOR: #ff6600"> [nc]</span></p> | ||
<p><strong>7. 阻止 User Agent 的所有请求</strong></p> | ||
<p><span style="COLOR: #ff6600">## .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]</span></p> | ||
<p><span style="COLOR: #ff6600">Order Allow,Deny<br/> | ||
Allow from all<br/> | ||
Deny from env=bad_bot</span></p> | ||
<p><span style="COLOR: #ff6600">## .htaccess Code :: END</span></p> | ||
<p><strong>8. 把某些特殊的IP地址的请求重定向到别的站点</strong></p> | ||
<p><span style="COLOR: #ff6600">ErrorDocument 403 </span><a href="http://www.youdomain.com/"><span style="COLOR: #ff6600">http://www.youdomain.com</span></a><br/> | ||
<span style="COLOR: #ff6600">Order deny,allow<br/> | ||
Deny from all<br/> | ||
Allow from 124.34.48.165<br/> | ||
Allow from 102.54.68.123</span></p> | ||
<p><strong>9. 直接找开文件而不是下载</strong> – 通常,我们打开网上文件的时候总是会出现一个对话框问我们是下载还是直接打开,使用下面的设置就不会出现这个问题了,直接打开。</p> | ||
<p><span style="COLOR: #ff6600">AddType application/octet-stream .pdf<br/> | ||
AddType application/octet-stream .zip<br/> | ||
AddType application/octet-stream .mov</span></p> | ||
<p><strong>10. 修改文件类型</strong> – 下面的示例可以让任何的文件都成为PHP那么被服务器解释。比如:myphp, cgi,phtml等。</p> | ||
<p><span style="COLOR: #ff6600">ForceType application/x-httpd-php<br/> | ||
SetHandler application/x-httpd-php</span></p> | ||
<p><strong>11. 阻止存取.htaccess 文件</strong></p> | ||
<p><span style="COLOR: #ff6600"># secure htaccess file</span></p> | ||
<p><span style="COLOR: #ff6600"> order allow,deny<br/> | ||
deny from all</span><br/> | ||
<strong>12. 保护服务器上的文件被存取</strong></p> | ||
<p><span style="COLOR: #ff6600"># prevent access of a certain file</span><span style="COLOR: #ff6600"> order allow,deny<br/> | ||
deny from all</span><br/> | ||
<strong>13. 阻止目录浏览</strong></p> | ||
<p><span style="COLOR: #ff6600"># disable directory browsing<br/> | ||
Options All -Indexes</span></p> | ||
<p><strong>14. 设置默认主页</strong></p> | ||
<p><span style="COLOR: #ff6600"># serve alternate default index page<br/> | ||
DirectoryIndex about.html</span></p> | ||
<p><strong>15. 口令认证</strong> – 你可以创建一个文件用于认证。下面是一个示例:</p> | ||
<p><span style="COLOR: #ff6600"># to protect a file</span></p> | ||
<p><span style="COLOR: #ff6600">AuthType Basic<br/> | ||
AuthName “Prompt”<br/> | ||
AuthUserFile /home/path/.htpasswd<br/> | ||
Require valid-user</span></p> | ||
<p><span style="COLOR: #ff6600"># 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</span></p> | ||
<p><strong>16. 把老的域名转像新的域名</strong></p> | ||
<p><span style="COLOR: #ff6600"># redirect from old domain to new domain<br/> | ||
RewriteEngine On<br/> | ||
RewriteRule ^(.*)$ </span><a href="http://www.yourdomain.com/$1"><span style="COLOR: #ff6600">http://www.yourdomain.com/$1</span></a><span style="COLOR: #ff6600"> [R=301,L]</span></p> | ||
<p><span style="color: #000000;">文章:<a href="http://rafeekphp.wordpress.com/2009/06/06/16-great-htaccess-tricks-and-hacks/" target="_blank">来源</a></span></p> | ||
<div style="margin-top: 15px; font-size: 16px;color: #cc0000;"> | ||
<p align="center"><strong>(转载本站文章请注明作者和出处 <a href="/">酷 壳 – CoolShell</a> ,请勿用于任何商业用途)</strong></p> | ||
</div> | ||
|
||
<div id="post-ratings-1035-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div> | ||
</div> | ||
<footer class="entry-footer"> | ||
<hr/><div class="row"><div class="col-md-6 cattegories"><span class="cat-links"><i class="fa fa-folder-open"></i> | ||
<a href="javascript:void(0)" rel="category tag">Web开发</a>, <a href="javascript:void(0)" rel="category tag">杂项资源</a></span></div><div class="col-md-6 tags"><span class="tags-links"><i class="fa fa-tags"></i> <a href="javascript:void(0)" rel="tag">.htaccess</a>, <a href="javascript:void(0)" rel="tag">Apache</a></span></div></div> </footer> | ||
</article> | ||
|
||
<div class="fixed"></div> | ||
</main> | ||
|
||
<div class="post-comments"> | ||
<div id="comments" class="comments-area"> | ||
<h2 class="comments-title"> | ||
《<span>16个简单实用的.htaccess小贴示</span>》的相关评论 </h2> | ||
<ol class="comment-list"> | ||
<li id="comment-228" class="comment even thread-even depth-1"> | ||
<article id="div-comment-228" class="comment-body"> | ||
<footer class="comment-meta"> | ||
<div class="comment-author vcard"> | ||
<img alt="" src="https://secure.gravatar.com/avatar/f4e0d44075ca64b360e2a7ae0fd32d62?s=50&d=mm&r=g" srcset="https://secure.gravatar.com/avatar/f4e0d44075ca64b360e2a7ae0fd32d62?s=100&d=mm&r=g 2x" class="avatar avatar-50 photo" height="50" width="50" loading="lazy" decoding="async"/> <b class="fn"><a href="http://claymore.phpme.info" class="url" rel="ugc external nofollow">Claymore</a></b><span class="says">说道:</span> </div> | ||
<div class="comment-metadata"> | ||
<a href="/articles/1035.html#comment-228"><time datetime="2009-06-14T13:44:01+08:00">2009年06月14日 13:44</time></a> </div> | ||
</footer> | ||
<div class="comment-content"> | ||
<p>哈哈,不错!<br/> | ||
好文章支持一个!</p> | ||
</div> | ||
</article> | ||
</li> | ||
<li id="comment-1177" class="comment odd alt thread-odd thread-alt depth-1"> | ||
<article id="div-comment-1177" class="comment-body"> | ||
<footer class="comment-meta"> | ||
<div class="comment-author vcard"> | ||
<img alt="" src="https://secure.gravatar.com/avatar/ae4dfd536e693cf53fce04a69ce48d60?s=50&d=mm&r=g" srcset="https://secure.gravatar.com/avatar/ae4dfd536e693cf53fce04a69ce48d60?s=100&d=mm&r=g 2x" class="avatar avatar-50 photo" height="50" width="50" loading="lazy" decoding="async"/> <b class="fn">吴鹏(AlphaWu)</b><span class="says">说道:</span> </div> | ||
<div class="comment-metadata"> | ||
<a href="/articles/1035.html#comment-1177"><time datetime="2009-09-26T13:32:23+08:00">2009年09月26日 13:32</time></a> </div> | ||
</footer> | ||
<div class="comment-content"> | ||
<p>不错的文章。。</p> | ||
</div> | ||
</article> | ||
</li> | ||
<li id="comment-9158" class="comment even thread-even depth-1"> | ||
<article id="div-comment-9158" class="comment-body"> | ||
<footer class="comment-meta"> | ||
<div class="comment-author vcard"> | ||
<img alt="" src="https://secure.gravatar.com/avatar/05cdbb54576585408d487d5e8aca534d?s=50&d=mm&r=g" srcset="https://secure.gravatar.com/avatar/05cdbb54576585408d487d5e8aca534d?s=100&d=mm&r=g 2x" class="avatar avatar-50 photo" height="50" width="50" loading="lazy" decoding="async"/> <b class="fn"><a href="http://liuxidong.myfreephp.tk" class="url" rel="ugc external nofollow">无缺</a></b><span class="says">说道:</span> </div> | ||
<div class="comment-metadata"> | ||
<a href="/articles/1035.html#comment-9158"><time datetime="2010-08-18T18:41:11+08:00">2010年08月18日 18:41</time></a> </div> | ||
</footer> | ||
<div class="comment-content"> | ||
<p>哇!这个超级有用啊,多谢!</p> | ||
</div> | ||
</article> | ||
</li> | ||
<li id="comment-73293" class="pingback odd alt thread-odd thread-alt depth-1"> | ||
<div class="comment-body"> | ||
Pingback: <a href="http://htm7.net/ten-web-development-articles-and-tutorials/" class="url" rel="ugc external nofollow">十个Web开发文章和教程 – xyyjk's blog - 专注前端开发、交互设计</a> </div> | ||
</li> | ||
<li id="comment-565533" class="pingback even thread-even depth-1"> | ||
<div class="comment-body"> | ||
Pingback: <a href="http://guanmian.net/?p=331" class="url" rel="ugc external nofollow">Apache mod_rewrite,Virtual Host,.htaccess files,mod_jk,mod_proxy_ajp | Steve Guan</a> </div> | ||
</li> | ||
<li id="comment-1222173" class="comment odd alt thread-odd thread-alt depth-1"> | ||
<article id="div-comment-1222173" class="comment-body"> | ||
<footer class="comment-meta"> | ||
<div class="comment-author vcard"> | ||
<img alt="" src="https://secure.gravatar.com/avatar/64c0ecd205d00cd44717590f1d7822e9?s=50&d=mm&r=g" srcset="https://secure.gravatar.com/avatar/64c0ecd205d00cd44717590f1d7822e9?s=100&d=mm&r=g 2x" class="avatar avatar-50 photo" height="50" width="50" loading="lazy" decoding="async"/> <b class="fn"><a href="http://www.smartwei.com" class="url" rel="ugc external nofollow">smileV</a></b><span class="says">说道:</span> </div> | ||
<div class="comment-metadata"> | ||
<a href="/articles/1035.html#comment-1222173"><time datetime="2014-01-24T17:42:55+08:00">2014年01月24日 17:42</time></a> </div> | ||
</footer> | ||
<div class="comment-content"> | ||
<p>阻止 User Agent 的所有请求:<br/> | ||
SetEnvIfNoCase语句后面少了bad_bot<br/> | ||
SetEnvIfNoCase user-Agent ^FrontPage bad_bot [NC,OR]<br/> | ||
…</p> | ||
</div> | ||
</article> | ||
</li> | ||
</ol> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</body></html> |
Oops, something went wrong.