.htaccess - 对 .htaccess 文件的更改使我的网站速度非常慢。我做错了什么,我该如何解决?

标签 .htaccess mod-rewrite google-analytics

我最近按照 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

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

最佳答案

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

这些行中的大多数都是无用的,因为您正在尝试阻止无法访问您网站的某些内容。唯一真正有用的是这 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

关于.htaccess - 对 .htaccess 文件的更改使我的网站速度非常慢。我做错了什么,我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30509937/

相关文章:

php - 允许服务器运行 cron 作业但使用 .htaccess 阻止普通用户访问

php - 替代 mod_expires 来设置过期 header ?

mod-rewrite - https://subdomain.example.com 重定向到 https://example.com:port

android - Firebase 与谷歌分析

filter - Google Analytics(分析)过滤器,用于结合/home.aspx和/

macos - MAMP 在哪里保存其 Web 服务器配置文件?

mysql - 如何更多地了解 MySQL、Apache 和 .htaccess?

apache - .htaccess mod_rewrite 循环

apache - 在 htaccess 文件中写入 if 条件以进行 url 重写

google-analytics - 从 Google Analytics(分析)中删除引荐