1. <var id="fe6gj"></var>

    <rp id="fe6gj"><nav id="fe6gj"></nav></rp>

    <noframes id="fe6gj"><cite id="fe6gj"></cite>

    <ins id="fe6gj"><button id="fe6gj"><p id="fe6gj"></p></button></ins>
    1. <tt id="fe6gj"><i id="fe6gj"><sub id="fe6gj"></sub></i></tt>
        始創于2000年 股票代碼:831685
        咨詢熱線:0371-60135900 注冊有禮 登錄
        • 掛牌上市企業
        • 60秒人工響應
        • 99.99%連通率
        • 7*24h人工
        • 故障100倍補償
        您的位置: 網站首頁 > 幫助中心>文章內容

        .htaccess學習筆記

        發布時間:  2012/8/11 9:12:02
         Apache的配置文件.htaccess是個難點,也是個重點。一直都沒安下心來好好學學,甚至一直以為Redirect方法是屬于mod_rewrite,用到的時候也都是糊里糊涂的。今天找到了一個很好的教程,一邊學,一邊寫點心得。

        updated: 不斷修正一些小問題

        Source: Comprehensive guide to .htaccess

        Officical reference: Directive Quick Reference

        1 Introduction 介紹
        文件名 .htaccess 屬性 644 (RW-R–R–)
        htaccess會影響它所在目錄下的所有子目錄
        注意大多數內容都要求保持在一行之內,不要換行,否則會引起錯誤

        2 Error Documents 錯誤文檔
        Official document: ErrorDocument Directive

        ErrorDocument code document
        例子
        ErrorDocument 400 /errors/badrequest.html
        ErrorDocument 404 http://yoursite/errors/notfound.html
        ErrorDocument 401 “Authorization Required”
        (注意之后內容如果出現的雙引號需要轉義為 \”)

        常見HTTP狀態碼

        Successful Client Requests

        200 OK
        201 Created
        202 Accepted
        203 Non-Authorative Information
        204 No Content
        205 Reset Content
        206 Partial Content

        Client Request Redirected

        300 Multiple Choices
        301 Moved Permanently
        302 Moved Temporarily
        303 See Other
        304 Not Modified
        305 Use Proxy

        Client Request Errors

        400 Bad Request
        401 Authorization Required
        402 Payment Required (not used yet)
        403 Forbidden
        404 Not Found
        405 Method Not Allowed
        406 Not Acceptable (encoding)
        407 Proxy Authentication Required
        408 Request Timed Out
        409 Conflicting Request
        410 Gone
        411 Content Length Required
        412 Precondition Failed
        413 Request Entity Too Long
        414 Request URI Too Long
        415 Unsupported Media Type

        Server Errors

        500 Internal Server Error
        501 Not Implemented
        502 Bad Gateway
        503 Service Unavailable
        504 Gateway Timeout
        505 HTTP Version Not Supported

        3 Password Protection 密碼保護
        Official document: Authentication, Authorization and Access Control

        假設密碼文件為.htpasswd

        AuthUserFile /usr/local/safedir/.htpasswd (這里必須使用全路徑名)
        AuthName EnterPassword
        AuthType Basic

        兩種常見驗證方式:
        Require user windix
        (僅允許用戶windix登陸)
        Require valid-user
        (所有合法用戶都可登陸)

        Tip: 如何生成密碼文件
        使用htpasswd命令(apache自帶)

        第一次生成需要創建密碼文件
        htpasswd -c .htpasswd user1

        之后增加新用戶
        htpasswd .htpasswd user2

        4 Enabling SSI Via htaccess 通過htaccess允許SSI(Server Side Including)功能
        AddType text/html .shtml
        AddHandler server-parsed .shtml
        Options Indexes FollowSymLinks Includes

        DirectoryIndex index.shtml index.html

        5 Blocking users by IP 根據IP阻止用戶訪問
        order allow,deny
        deny from 123.45.6.7
        deny from 12.34.5. (整個C類地址)
        allow from all

        6 Blocking users/sites by referrer 根據referrer阻止用戶/站點訪問
        需要mod_rewrite模塊

        例1. 阻止單一referrer: badsite.com
        RewriteEngine on
        # Options +FollowSymlinks
        RewriteCond %{HTTP_REFERER} badsite\.com [NC]
        RewriteRule .* - [F]

        例2. 阻止多個referrer: badsite1.com, badsite2.com
        RewriteEngine on
        # Options +FollowSymlinks
        RewriteCond %{HTTP_REFERER} badsite1\.com [NC,OR]
        RewriteCond %{HTTP_REFERER} badsite2\.com
        RewriteRule .* - [F]

        [NC] - 大小寫不敏感(Case-insensite)
        [F] - 403 Forbidden

        注意以上代碼注釋掉了”Options +FollowSymlinks”這個語句。如果服務器未在 httpd.conf 的 段落設置 FollowSymLinks, 則需要加上這句,否則會得到”500 Internal Server error”錯誤。

        7 Blocking bad bots and site rippers (aka offline browsers) 阻止壞爬蟲和離線瀏覽器
        需要mod_rewrite模塊

        壞爬蟲? 比如一些抓垃圾email地址的爬蟲和不遵守robots.txt的爬蟲(如baidu?)
        可以根據 HTTP_USER_AGENT 來判斷它們
        (但是還有更無恥的如”中搜 zhongsou.com”之流把自己的agent設置為 “Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)” 太流氓了,就無能為力了)

        RewriteEngine On
        RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
        RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
        RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
        RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
        RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]


        本文出自:億恩科技【www.endtimedelusion.com】

        服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質保障!--億恩科技[ENKJ.COM]

      1. 您可能在找
      2. 億恩北京公司:
      3. 經營性ICP/ISP證:京B2-20150015
      4. 億恩鄭州公司:
      5. 經營性ICP/ISP/IDC證:豫B1.B2-20060070
      6. 億恩南昌公司:
      7. 經營性ICP/ISP證:贛B2-20080012
      8. 服務器/云主機 24小時售后服務電話:0371-60135900
      9. 虛擬主機/智能建站 24小時售后服務電話:0371-60135900
      10. 專注服務器托管17年
        掃掃關注-微信公眾號
        0371-60135900
        Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權所有  地址:鄭州市高新區翠竹街1號總部企業基地億恩大廈  法律顧問:河南亞太人律師事務所郝建鋒、杜慧月律師   京公網安備41019702002023號
          0
         
         
         
         

        0371-60135900
        7*24小時客服服務熱線

         
         
        av不卡不卡在线观看_最近2018年中文字幕_亚洲欧美一区二区三区_一级A爱做片免费观看国产_日韩在线中文天天更新_伊人中文无码在线