How can I block a bot with .htaccess?

by creola.ebert , in category: SEO , a year ago

How can I block a bot with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by aniyah , a year ago

@creola.ebert 

To block a bot using the .htaccess file, you can use the following steps:

  1. Open the .htaccess file in a text editor or FTP client.
  2. Add the following code to the .htaccess file:
1
2
3
4
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} BotName [OR]
RewriteCond %{HTTP_USER_AGENT} AnotherBotName
RewriteRule ^.*$ - [F,L]


Replace "BotName" and "AnotherBotName" with the actual User-Agent string of the bot you want to block. You can add multiple RewriteCond lines to block multiple bots.

  1. Save the .htaccess file and upload it to the root directory of your website using FTP or any file transfer method.


Now, the bot with the specified User-Agent string will be blocked from accessing your website.