{"id":1271,"date":"2009-06-15T14:17:38","date_gmt":"2009-06-15T06:17:38","guid":{"rendered":"https:\/\/www.wopus.org\/?p=1271"},"modified":"2009-06-15T14:17:38","modified_gmt":"2009-06-15T06:17:38","slug":"16%e4%b8%aa%e7%ae%80%e5%8d%95%e5%ae%9e%e7%94%a8%e7%9a%84htaccess%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/wopus.org\/?p=1271","title":{"rendered":"16\u4e2a\u7b80\u5355\u5b9e\u7528\u7684.htaccess\u6280\u5de7"},"content":{"rendered":"<p>.htaccess \u6587\u4ef6 (Hypertext Access file) \u662fApache Web\u670d\u52a1\u5668\u7684\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5bf9\u4e8e\u8fd9\u4e2a\u6587\u4ef6\uff0cApache\u6709\u4e00\u5806\u53c2\u6570\u53ef\u4ee5\u8ba9\u4f60\u914d\u7f6e\u51fa\u51e0\u4e4e\u968f\u5fc3\u6240\u6b32\u7684\u529f\u80fd\u3002.htaccess \u914d\u7f6e\u6587\u4ef6\u575a\u6301\u4e86Unix\u7684\u4e00\u4e2a\u6587\u5316\u2014\u2014\u4f7f\u7528\u4e00\u4e2aASCII \u7684\u7eaf\u6587\u672c\u6587\u4ef6\u6765\u914d\u7f6e\u4f60\u7684\u7f51\u7ad9\u7684\u8bbf\u95ee\u7b56\u7565\u3002<\/p>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u5305\u62ec\u4e8616\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5c0f\u6280\u5de7\u3002\u53e6\u5916\uff0c\u56e0\u4e3a.htaccess \u662f\u4e00\u4e2a\u76f8\u5f53\u5f3a\u5927\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u6240\u4ee5\uff0c\u4e00\u4e2a\u8f7b\u5fae\u7684\u8bed\u6cd5\u9519\u8bef\u4f1a\u9020\u6210\u4f60\u6574\u4e2a\u7f51\u7ad9\u7684\u6545\u969c\uff0c\u6240\u4ee5\uff0c\u5728\u4f60\u4fee\u6539\u6216\u662f\u66ff\u6362\u539f\u6709\u7684\u6587\u4ef6\u65f6\uff0c\u4e00\u5b9a\u8981\u5907\u4efd\u65e7\u7684\u6587\u4ef6\uff0c\u4ee5\u4fbf\u51fa\u73b0\u95ee\u9898\u7684\u65f6\u5019\u53ef\u4ee5\u65b9\u4fbf\u7684\u6062\u590d\u3002<\/p>\n<p><strong>1. \u4f7f\u7528.htaccess \u521b\u5efa\u81ea\u5b9a\u4e49\u7684\u51fa\u9519\u9875\u9762\u3002\u5bf9\u4e8eLinux Apache\u6765\u8bf4\u8fd9\u662f\u4e00\u9879\u6781\u5176\u7b80\u5355\u7684\u4e8b\u60c5\u3002\u4f7f\u7528\u4e0b\u9762\u7684.htaccess\u8bed\u6cd5\u4f60\u53ef\u4ee5\u8f7b\u677e\u7684\u5b8c\u6210\u8fd9\u4e00\u529f\u80fd\u3002\uff08\u628a.htaccess\u653e\u5728\u4f60\u7684\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\uff09<\/strong><\/p>\n<blockquote><p>\nErrorDocument 401 \/error\/401.php<br \/>\nErrorDocument 403 \/error\/403.php<br \/>\nErrorDocument 404 \/error\/404.php<br \/>\nErrorDocument 500 \/error\/500.php\n<\/p><\/blockquote>\n<p><strong>2. \u8bbe\u7f6e\u7f51\u7ad9\u7684\u65f6\u533a<\/strong><\/p>\n<blockquote><p>\nSetEnv TZ America\/Houston\n<\/p><\/blockquote>\n<p><strong>3. \u963b\u6b62IP\u5217\u8868<\/strong><br \/>\n\u6709\u4e9b\u65f6\u5019\uff0c\u4f60\u9700\u8981\u4ee5IP\u5730\u5740\u7684\u65b9\u5f0f\u963b\u6b62\u4e00\u4e9b\u8bbf\u95ee\u3002\u65e0\u8bba\u662f\u5bf9\u4e8e\u4e00\u4e2aIP\u5730\u5740\u8fd8\u662f\u4e00\u4e2a\u7f51\u6bb5\uff0c\u8fd9\u90fd\u662f\u4e00\u4ef6\u975e\u5e38\u7b80\u5355\u7684\u4e8b\u60c5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<blockquote><p>\nallow from all<br \/>\ndeny from 145.186.14.122<br \/>\ndeny from 124.15\n<\/p><\/blockquote>\n<p>Apache\u5bf9\u4e8e\u88ab\u62d2\u7edd\u7684IP\u4f1a\u8fd4\u56de403\u9519\u8bef\u3002<\/p>\n<p><strong>4. \u628a\u4e00\u4e9b\u8001\u7684\u94fe\u63a5\u8f6c\u5230\u65b0\u7684\u94fe\u63a5\u4e0a\u2014\u2014\u641c\u7d22\u5f15\u64ce\u4f18\u5316SEO<\/strong><\/p>\n<blockquote><p>\nRedirect 301 \/d\/file.html http:\/\/www.htaccesselite.com\/r\/file.html\n<\/p><\/blockquote>\n<p><strong>5. \u4e3a\u670d\u52a1\u5668\u7ba1\u7406\u5458\u8bbe\u7f6e\u7535\u5b50\u90ae\u4ef6\u3002<\/strong><\/p>\n<blockquote><p>\nServerSignature EMail<br \/>\nSetEnv SERVER_ADMIN default@domain.com\n<\/p><\/blockquote>\n<p><strong>6. \u4f7f\u7528.htaccess \u8bbf\u6b62\u76d7\u94fe\u3002\u5982\u679c\u4f60\u7f51\u7ad9\u4e0a\u7684\u4e00\u4e2a\u56fe\u7247\u88ab\u522b\u7684N\u591a\u7684\u7f51\u7ad9\u5f15\u7528\u4e86\uff0c\u90a3\u4e48\uff0c\u8fd9\u5f88\u6709\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4f60\u670d\u52a1\u5668\u7684\u6027\u80fd\u4e0b\u964d\uff0c\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u4fdd\u62a4\u67d0\u4e9b\u70ed\u95e8\u7684\u94fe\u63a5\u4e0d\u88ab\u8fc7\u591a\u7684\u5f15\u7528\u3002<\/strong><\/p>\n<blockquote><p>\nOptions +FollowSymlinks<br \/>\n# Protect Hotlinking<br \/>\nRewriteEngine On<br \/>\nRewriteCond %{HTTP_REFERER} !^$<br \/>\nRewriteCond %{HTTP_REFERER} !^http:\/\/(www.)?domainname.com\/ [nc]<br \/>\nRewriteRule .*.(gif|jpg|png)$ http:\/\/domainname.com\/img\/hotlink_f_o.png [nc]\n<\/p><\/blockquote>\n<p><strong>7. \u963b\u6b62 User Agent \u7684\u6240\u6709\u8bf7\u6c42<\/strong><\/p>\n<blockquote><p>\n## .htaccess Code :: BEGIN<br \/>\n## Block Bad Bots by user-Agent<br \/>\nSetEnvIfNoCase user-Agent ^FrontPage [NC,OR]<br \/>\nSetEnvIfNoCase user-Agent ^Java.* [NC,OR]<br \/>\nSetEnvIfNoCase user-Agent ^Microsoft.URL [NC,OR]<br \/>\nSetEnvIfNoCase user-Agent ^MSFrontPage [NC,OR]<br \/>\nSetEnvIfNoCase user-Agent ^Offline.Explorer [NC,OR]<br \/>\nSetEnvIfNoCase user-Agent ^[Ww]eb[Bb]andit [NC,OR]<br \/>\nSetEnvIfNoCase user-Agent ^Zeus [NC]<\/p>\n<p>Order Allow,Deny<br \/>\nAllow from all<br \/>\nDeny from env=bad_bot<\/p>\n<p>## .htaccess Code :: END\n<\/p><\/blockquote>\n<p><strong>8. \u628a\u67d0\u4e9b\u7279\u6b8a\u7684IP\u5730\u5740\u7684\u8bf7\u6c42\u91cd\u5b9a\u5411\u5230\u522b\u7684\u7ad9\u70b9<\/strong><\/p>\n<blockquote><p>\nErrorDocument 403 http:\/\/www.youdomain.com<br \/>\nOrder deny,allow<br \/>\nDeny from all<br \/>\nAllow from ip<br \/>\nAllow from ip\n<\/p><\/blockquote>\n<p><strong>9. \u76f4\u63a5\u627e\u5f00\u6587\u4ef6\u800c\u4e0d\u662f\u4e0b\u8f7d \u2013 \u901a\u5e38\uff0c\u6211\u4eec\u6253\u5f00\u7f51\u4e0a\u6587\u4ef6\u7684\u65f6\u5019\u603b\u662f\u4f1a\u51fa\u73b0\u4e00\u4e2a\u5bf9\u8bdd\u6846\u95ee\u6211\u4eec\u662f\u4e0b\u8f7d\u8fd8\u662f\u76f4\u63a5\u6253\u5f00\uff0c\u4f7f\u7528\u4e0b\u9762\u7684\u8bbe\u7f6e\u5c31\u4e0d\u4f1a\u51fa\u73b0\u8fd9\u4e2a\u95ee\u9898\u4e86\uff0c\u76f4\u63a5\u6253\u5f00<\/strong>\u3002<\/p>\n<blockquote><p>\nAddType application\/octet-stream .pdf<br \/>\nAddType application\/octet-stream .zip<br \/>\nAddType application\/octet-stream .mov\n<\/p><\/blockquote>\n<p><strong>10. \u4fee\u6539\u6587\u4ef6\u7c7b\u578b \u2013 \u4e0b\u9762\u7684\u793a\u4f8b\u53ef\u4ee5\u8ba9\u4efb\u4f55\u7684\u6587\u4ef6\u90fd\u6210\u4e3aPHP\u90a3\u4e48\u88ab\u670d\u52a1\u5668\u89e3\u91ca\u3002\u6bd4\u5982\uff1amyphp, cgi\uff0cphtml\u7b49\u3002<\/strong><\/p>\n<blockquote><p>\nForceType application\/x-httpd-php<br \/>\nSetHandler application\/x-httpd-php\n<\/p><\/blockquote>\n<p><strong>11. \u963b\u6b62\u5b58\u53d6.htaccess \u6587\u4ef6<\/strong><\/p>\n<blockquote><p>\n# secure htaccess file<br \/>\n order allow,deny<br \/>\n deny from all\n<\/p><\/blockquote>\n<p><strong>12. \u4fdd\u62a4\u670d\u52a1\u5668\u4e0a\u7684\u6587\u4ef6\u88ab\u5b58\u53d6<\/strong><\/p>\n<blockquote><p>\n# prevent access of a certain file order allow,deny<br \/>\n deny from all\n<\/p><\/blockquote>\n<p><strong>13. \u963b\u6b62\u76ee\u5f55\u6d4f\u89c8<\/strong><\/p>\n<blockquote><p>\n# disable directory browsing<br \/>\nOptions All -Indexes\n<\/p><\/blockquote>\n<p><strong>14. \u8bbe\u7f6e\u9ed8\u8ba4\u4e3b\u9875<\/strong><\/p>\n<blockquote><p>\n# serve alternate default index page<br \/>\nDirectoryIndex about.html\n<\/p><\/blockquote>\n<p><strong>15. \u53e3\u4ee4\u8ba4\u8bc1 \u2013 \u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u7528\u4e8e\u8ba4\u8bc1\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/strong><\/p>\n<blockquote><p>\n# to protect a file<\/p>\n<p>AuthType Basic<br \/>\nAuthName \u201cPrompt\u201d<br \/>\nAuthUserFile \/home\/path\/.htpasswd<br \/>\nRequire valid-user<\/p>\n<p># password-protect a directory<br \/>\nresides<br \/>\nAuthType basic<br \/>\nAuthName \u201cThis directory is protected\u201d<br \/>\nAuthUserFile \/home\/path\/.htpasswd<br \/>\nAuthGroupFile \/dev\/null<br \/>\nRequire valid-user\n<\/p><\/blockquote>\n<p><strong>16. \u628a\u8001\u7684\u57df\u540d\u8f6c\u50cf\u65b0\u7684\u57df\u540d<\/strong><\/p>\n<blockquote><p>\n# redirect from old domain to new domain<br \/>\nRewriteEngine On<br \/>\nRewriteRule ^(.*)$ http:\/\/www.yourdomain.com\/$1 [R=301,L]\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>.htaccess \u6587\u4ef6 (Hypertext Access file) \u662fApache Web\u670d\u52a1\u5668\u7684\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5bf9\u4e8e\u8fd9\u4e2a\u6587\u4ef6\uff0cApache\u6709\u4e00\u5806\u53c2\u6570\u53ef\u4ee5\u8ba9\u4f60\u914d\u7f6e\u51fa\u51e0\u4e4e\u968f\u5fc3\u6240\u6b32\u7684\u529f\u80fd\u3002.htaccess \u914d\u7f6e\u6587\u4ef6\u575a\u6301\u4e86Unix\u7684\u4e00\u4e2a\u6587\u5316\u2014\u2014\u4f7f\u7528\u4e00\u4e2aASCII \u7684\u7eaf\u6587\u672c\u6587\u4ef6\u6765\u914d\u7f6e\u4f60\u7684\u7f51\u7ad9\u7684\u8bbf\u95ee\u7b56\u7565\u3002 \u8fd9\u7bc7\u6587\u7ae0\u5305\u62ec\u4e8616\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5c0f\u6280\u5de7\u3002\u53e6\u5916\uff0c\u56e0\u4e3a.htaccess \u662f\u4e00\u4e2a\u76f8\u5f53\u5f3a\u5927\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u6240\u4ee5\uff0c\u4e00\u4e2a\u8f7b\u5fae\u7684\u8bed\u6cd5\u9519\u8bef\u4f1a\u9020\u6210\u4f60\u6574\u4e2a\u7f51\u7ad9\u7684\u6545\u969c\uff0c\u6240\u4ee5\uff0c\u5728\u4f60\u4fee\u6539\u6216\u662f\u66ff\u6362\u539f\u6709\u7684\u6587\u4ef6\u65f6\uff0c\u4e00\u5b9a\u8981\u5907\u4efd\u65e7\u7684\u6587\u4ef6\uff0c\u4ee5\u4fbf\u51fa\u73b0\u95ee\u9898\u7684\u65f6\u5019\u53ef\u4ee5\u65b9\u4fbf\u7684\u6062\u590d\u3002 1. \u4f7f\u7528.htaccess \u521b\u5efa\u81ea\u5b9a\u4e49\u7684\u51fa\u9519\u9875\u9762\u3002\u5bf9\u4e8eLinux Apache\u6765\u8bf4\u8fd9\u662f\u4e00\u9879\u6781\u5176\u7b80\u5355\u7684\u4e8b\u60c5\u3002\u4f7f\u7528\u4e0b\u9762\u7684.htaccess\u8bed\u6cd5\u4f60\u53ef\u4ee5\u8f7b\u677e\u7684\u5b8c\u6210\u8fd9\u4e00\u529f\u80fd\u3002\uff08\u628a.htaccess\u653e\u5728\u4f60\u7684\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\uff09 ErrorDocument 401 \/error\/401.php ErrorDocument 403 \/error\/403.php ErrorDocument 404 \/error\/404.php ErrorDocument 500 \/error\/500.php 2. \u8bbe\u7f6e\u7f51\u7ad9\u7684\u65f6\u533a SetEnv TZ America\/Houston 3. \u963b\u6b62IP\u5217\u8868 \u6709\u4e9b\u65f6\u5019\uff0c\u4f60\u9700\u8981\u4ee5IP\u5730\u5740\u7684\u65b9\u5f0f\u963b\u6b62\u4e00\u4e9b\u8bbf\u95ee\u3002\u65e0\u8bba\u662f\u5bf9\u4e8e\u4e00\u4e2aIP\u5730\u5740\u8fd8\u662f\u4e00\u4e2a\u7f51\u6bb5\uff0c\u8fd9\u90fd\u662f\u4e00\u4ef6\u975e\u5e38\u7b80\u5355\u7684\u4e8b\u60c5\uff0c\u5982\u4e0b\u6240\u793a\uff1a allow from all deny from 145.186.14.122 deny from 124.15 Apache\u5bf9\u4e8e\u88ab\u62d2\u7edd\u7684IP\u4f1a\u8fd4\u56de403\u9519\u8bef\u3002 4. \u628a\u4e00\u4e9b\u8001\u7684\u94fe\u63a5\u8f6c\u5230\u65b0\u7684\u94fe\u63a5\u4e0a\u2014\u2014\u641c\u7d22\u5f15\u64ce\u4f18\u5316SEO Redirect 301 \/d\/file.html http:\/\/www.htaccesselite.com\/r\/file.html 5. \u4e3a\u670d\u52a1\u5668\u7ba1\u7406\u5458\u8bbe\u7f6e\u7535\u5b50\u90ae\u4ef6\u3002 ServerSignature EMail [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[57,58,71],"class_list":["post-1271","post","type-post","status-publish","format-standard","hentry","category-tech","tag-htaccess","tag-71"],"_links":{"self":[{"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/posts\/1271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wopus.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1271"}],"version-history":[{"count":0,"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/posts\/1271\/revisions"}],"wp:attachment":[{"href":"https:\/\/wopus.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wopus.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wopus.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}