分享
  • 收藏
  • 举报
    X
    Apache中正确设置.htaccess文件,可以明显减少服务器资源损耗
    87
    1

    Apache中正确设置.htaccess文件,可以明显减少服务器资源损耗。我原本服务器的负载和CPU一直标高,经过这么一改,现在非常正常了。


    <IfModule mod_rewrite.c>

      Options +FollowSymlinks -Multiviews

      RewriteEngine On

      

    #屏蔽垃圾蜘蛛

    SetEnvIfNoCase ^User-Agent$ .*(DataForSeoBot/1.0|dataforseo-bot|SemrushBot|SemrushBot-SA|Scrapy/1.7.3|Bytespider|BLEXBot|CompSpyBot|Exabot|Adsbot/3.1|serpstatbot/2.1|ZoominfoBot|ExtLinksBot|AlphaBot|DotBot|MauiBot|MegaIndex.ru|CCBot/2.0|SiteExplorer|Webdup|AcoonBot|AhrefsBot|Ezooms|EdisterBot|EC2LinkFinder|jikespider|Purebot|MJ12bot|WangIDSpider|WBSearchBot|Wotbox|xbfMozilla|Yottaa|Jorgee|SWEBot|spbot|TurnitinBot-Agent|AhrefsBot|perl|Python|Wget|Xenu|thesis-research-bot|ImagesiftBot|my-tiny-bot|Scrapy/1.5.1|Go-http-client/1.1|Yisou|facebook|gptbot|amazonbot|ZmEu) BADBOT


    Order Allow,Deny


    Allow from all


    Deny from env=BADBOT

    ErrorDocument 404 /404.html


    #  拦截恶意请求,过滤常见攻击特征(如SQL注入尝试)

      RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]

      RewriteCond %{QUERY_STRING} (eval\(|union.*select) [NC]

      RewriteRule .* - [F,L]


    # 正常规则

      RewriteCond %{REQUEST_FILENAME} !-d

      RewriteCond %{REQUEST_FILENAME} !-f

    # RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

      RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

    </IfModule>


    0
    赏礼
    赏钱
    收藏
    点击回复
        全部留言
    • 1
    0 赏钱 赏礼回复
    更多回复
        你可能感兴趣的主题
    恢复多功能编辑器
  • 3 1
  • 推荐内容
    扫一扫访问手机版
    请选择要切换的马甲:

     
    网页即时交流
    QQ咨询
    咨询热线
    020-28998648