Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [.htaccess] Problem z blokowaniem robotów
Forum PHP.pl > Forum > Serwery WWW
Przekras
Witam,
chciałem dodać do swojej strony blokowanie niektórych robotów, na jednej ze stron znalazłem listę robotów i dodałem kilka swoich(lista jest dłuższa niż na dole). Przed zmianami plik .htaccess wyglądał tak (wszystko dobrze działało, a czy wydajnie to nie wiem):

  1. RewriteEngine On
  2. RewriteCond %{HTTP_HOST} ^strona.com$ [NC]
  3. RewriteRule ^(.*)$ http://www.strona.com/$1 [R=301,L]
  4. RewriteBase /
  5. RewriteCond %{REQUEST_URI} ^/index.php$
  6. RewriteCond %{QUERY_STRING} ^$
  7. RewriteRule ^(.*)$ http://www.strona.com/$ [R=301,L]
  8. RewriteRule ^rss.xml$ /rss.php [L]
  9. RewriteRule ^sitemap.xml$ /sitemap.php [L]
  10. RewriteRule ^([a-zA-Z0-9-]+)/$ http://%{HTTP_HOST}/$1 [R=301]
  11. RewriteRule ^site-([0-9]+)$ index.php?page=$1 [L,NC]
  12. RewriteRule ^([a-z-]+)$ index.php?aba=$1 [L,NC]
  13. RewriteRule ^([a-z-]+)/([a-zA-Z0-9-]+)/$ http://%{HTTP_HOST}/$1/$2 [R=301]
  14. RewriteRule ^([a-z-]+)/site-([0-9]+)$ index.php?aba=$1&page=$2 [L,NC]
  15. RewriteRule ^([a-z-]+)/([0-9]+)/([^*]+)/$ http://%{HTTP_HOST}/$1/$2/$3 [R=301]
  16. RewriteRule ^([a-z-]+)/([0-9]+)/([^*]+)$ index.php?aba=$1&id=$2&titleurl=$3 [L,NC]
  17. RewriteRule ^([a-z-]+)/([a-zA-Z0-9-]+)/([a-z-]+)/([a-zA-Z0-9-]+)/$ http://%{HTTP_HOST}/$1/$2/$3/$4 [R=301]
  18. RewriteRule ^([a-z-]+)/([a-zA-Z0-9-]+)/([a-z-]+)/site-([0-9]+)$ index.php?aba=$1&category=$2&titleurl=$3&page=$4 [L,NC]
  19. ErrorDocument 404 http://www.strona.com/
  20. ErrorDocument 403 http://www.strona.com/


Zmieniłem na taki:

  1. RewriteEngine On
  2. RewriteCond %{HTTP_HOST} ^strona.com$ [NC]
  3. RewriteRule ^(.*)$ http://www.strona.com/$1 [R=301,L]
  4. RewriteBase /
  5. RewriteCond %{REQUEST_URI} ^/index.php$
  6. RewriteCond %{QUERY_STRING} ^$
  7. RewriteRule ^(.*)$ http://www.strona.com/$ [R=301,L]
  8. RewriteRule ^rss.xml$ /rss.php [L]
  9. RewriteRule ^sitemap.xml$ /sitemap.php [L]
  10. RewriteRule ^([a-zA-Z0-9-]+)/$ http://%{HTTP_HOST}/$1 [R=301]
  11. RewriteRule ^site-([0-9]+)$ index.php?page=$1 [L,NC]
  12. RewriteRule ^([a-z-]+)$ index.php?aba=$1 [L,NC]
  13. RewriteRule ^([a-z-]+)/([a-zA-Z0-9-]+)/$ http://%{HTTP_HOST}/$1/$2 [R=301]
  14. RewriteRule ^([a-z-]+)/site-([0-9]+)$ index.php?aba=$1&page=$2 [L,NC]
  15. RewriteRule ^([a-z-]+)/([0-9]+)/([^*]+)/$ http://%{HTTP_HOST}/$1/$2/$3 [R=301]
  16. RewriteRule ^([a-z-]+)/([0-9]+)/([^*]+)$ index.php?aba=$1&id=$2&titleurl=$3 [L,NC]
  17. RewriteRule ^([a-z-]+)/([a-zA-Z0-9-]+)/([a-z-]+)/([a-zA-Z0-9-]+)/$ http://%{HTTP_HOST}/$1/$2/$3/$4 [R=301]
  18. RewriteRule ^([a-z-]+)/([a-zA-Z0-9-]+)/([a-z-]+)/site-([0-9]+)$ index.php?aba=$1&category=$2&titleurl=$3&page=$4 [L,NC]
  19. ## SITE REFERRER BANNING
  20. RewriteCond %{HTTP_REFERER} Traffic2cash.xyz [NC,OR]
  21. RewriteCond %{HTTP_REFERER} Share-buttons.xyz [NC]
  22. RewriteRule .* - [F]
  23. ## Bad bot
  24. SetEnvIfNoCase User-Agent "abot" bad_bot
  25. SetEnvIfNoCase User-Agent "AhrefsBot" bad_bot
  26. SetEnvIfNoCase User-Agent "aipbot" bad_bot
  27. SetEnvIfNoCase User-Agent "asterias" bad_bot
  28. SetEnvIfNoCase User-Agent "bingbot" bad_bot
  29. SetEnvIfNoCase User-Agent "EI" bad_bot
  30. SetEnvIfNoCase User-Agent "Blogshares Spiders" bad_bot
  31. SetEnvIfNoCase User-Agent "Board Bot" bad_bot
  32. SetEnvIfNoCase User-Agent "Board Bot" bad_bot
  33. SetEnvIfNoCase User-Agent "Convera" bad_bot
  34. SetEnvIfNoCase User-Agent "ConveraMultiMediaCrawler" bad_bot
  35. SetEnvIfNoCase User-Agent "c-spider" bad_bot
  36. SetEnvIfNoCase User-Agent "Yandex" bad_bot
  37. SetEnvIfNoCase User-Agent "YandexBot" bad_bot
  38. SetEnvIfNoCase User-Agent "zerxbot" bad_bot
  39. # Apache < 2.4
  40. <IfModule !mod_authz_core.c>
  41. <Limit GET POST>
  42. Order allow,deny
  43. Allow from all
  44. Deny from env=bad_bot
  45. </Limit>
  46. </IfModule>
  47. # Apache >= 2.4
  48. <IfModule mod_authz_core.c>
  49. <Limit GET POST>
  50. <RequireAll>
  51. Require all granted
  52. Require not env bad_bot
  53. </RequireAll>
  54. </Limit>
  55. </IfModule>
  56. ErrorDocument 404 http://www.strona.com/
  57. ErrorDocument 403 http://www.strona.com/


Po zmianie roboty nie są blokowane (sprawdziłem w logach). Nie znam się za bardzo na plikach .htaccess, co mogę zmienić żeby to działało i miało dobrą wydajność?
darko
W osobnym pliku tekstowym o nazwie robots.txt wpisz:

User-agent: *
Disallow: /

Co do wydajności to się nie wypowiem.
Źródło: http://www.robotstxt.org/robotstxt.html
Przekras
Cytat(darko @ 11.01.2016, 23:05:56 ) *
W osobnym pliku tekstowym o nazwie robots.txt wpisz:

User-agent: *
Disallow: /

Co do wydajności to się nie wypowiem.
Źródło: http://www.robotstxt.org/robotstxt.html

Chcę zablokować dostęp tylko niektórych robotów i zrobić to przez .htaccess, bo niektóre roboty nie zwracają uwagi na robots.txt
darko
Zerknij tutaj: http://en.linuxreviews.org/HOWTO_stop_auto...using_.htaccess
Przekras
Dzisiaj sprawdziłem funkcją "mail" czy blokada w .htaccess działa, tzn przy każdym wejściu na stronę wysyłało mi maila z informacją o User_Agent, i jednak blokada w .htaccess działa. Mimo iż bot nie pobiera zasobów strony, to jest pokazywany w logach, a do pliku index.php już się nie dostaje o czym nie wiedziałem. Także problem rozwiązany, dzięki za pomoc darko
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.