【问题标题】:Changes to my .htaccess file made my site very slow. What did I do wrong, and how can I fix?对我的 .htaccess 文件的更改使我的网站变得非常慢。我做错了什么,我该如何解决?
【发布时间】:2015-05-28 14:49:15
【问题描述】:

我最近按照http://www.roimarketing.co.nz/articles/what-is-referrer-spam-how-can-you-block-it/ 上的说明对我的 .htaccess 文件进行了更改

我一直遇到机器人爬取我的网站并使其难以解释分析的问题。添加上面链接中显示的代码后,该站点需要一分钟以上的时间来加载每个页面,而之前只需要 5 秒。我做错了什么,我该如何解决?我很可能犯了一个被我忽略的菜鸟错误。

相关网站:royalelectric.com

我编辑了 /public_html/ 目录中的 .htaccess 文件。

这是我的旧 .htaccess 文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

这是我的新 .htaccess 文件:

## STOP REFERRER SPAM ##
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?4webmasters\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?site1.free-share-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?site2.free-share-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?site3.free-share-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?site4.free-share-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?anticrawler\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?addons\.mozilla\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?baidu\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?bestwebsitesawards\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?best-seo-solution\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?best-seo-offer\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?blackhatworth\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?buttons-for-website\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?buttons-for-your-website\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?buy-cheap-online\.info [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?econom\.co [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?darodar\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?sanjosestartups\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?free-social-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?guardlink\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?event-tracking\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?domination\.ml [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?hulfingtonpost\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?Get-Free-Traffic-Now\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?googlsucks\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?free-share-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?humanorightswatch\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?ilovevitaly\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?7makemoneyonline\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?o-o-6-o-o\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?priceg\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?social-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?semalt\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?smailik\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?theguardlan\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?simple-share-buttons\.com [NC]
RewriteRule .* – [F]
## STOP REFERRER SPAM ##


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

您可以在这里给我的任何帮助将不胜感激,因为我厌倦了处理破坏我的分析的机器人,但我不想牺牲加载时间来解决问题。 谢谢!

【问题讨论】:

  • 添加RewriteCond 堆栈来检测爬虫似乎极不可能大大降低您的网站速度,即使在非常糟糕且资源有限的 Apache 服务器上也是如此。我不得不问-您是否已将其注释掉以验证它确实是导致性能问题的 .htaccess ?
  • 我对 .htaccess 文件进行更改后,网站速度变慢了。今天早上早些时候,它一直在快速工作/加载。我尝试将新代码放在现有代码的上方和下方,那里的加载时间似乎没有差异。
  • 我刚刚加载了您的站点并观看了网络控制台(对我来说加载大约需要 10 秒)。您加载了大量图像资源,Apache 将为每个图像请求处理 RewriteCond。如果您注释掉新规则并且它再次变快,则可以告诉 Apache 跳过所有对 .png、.jpg、.gif 资源的引用检查。
  • 我对处理 html 和 css 之外的任何东西都很陌生,但是 sn-p 会跳过所有对 .png、.jpg、.gif 资源的引用检查。 ?感谢您的帮助。
  • 是这个吗? RewriteRule .*\.jpg - [S] RewriteRule .*\.png - [S] RewriteRule .*\.jpeg - [S] RewriteRule .*\.gif - [S]

标签: .htaccess mod-rewrite google-analytics


【解决方案1】:

简单的重写规则不应降低您的网站速度。除非有一些错误的代码导致它,否则请检查其余代码是否正常,并且由于此文件非常敏感在编辑之前请务必备份,因为它可能会关闭您的网站。

这些行中的大部分都是无用的,因为您试图阻止无法访问您网站的内容。唯一真正有用的是来自爬虫的这 5 个

## STOP REFERRER SPAM ##
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?best-seo-solution\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?best-seo-offer\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?7makemoneyonline\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?buttons-for-website\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^([^.]+.)*?buttons-for-your-website\.com [NC]
RewriteRule .* – [F]
## STOP REFERRER SPAM ##

为了保持您的.htaccess 文件干净,您应该删除其余部分,因为那是幽灵垃圾邮件,它与您的网站没有任何互动,这就是这些规则确实,阻止访问您的网站。

幽灵垃圾邮件直接命中您的报告,因此阻止它们唯一的解决方案是在 Google Analytics(分析)中创建过滤器

您可以在此处找到有关解决方案和垃圾邮件的更多信息

https://stackoverflow.com/a/28354319/3197362

https://stackoverflow.com/a/29645325/3197362

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    相关资源
    最近更新 更多