user1609391
user1609391

Reputation: 455

Blocking bots by modifying htaccess

I am trying to block a couple bots via my htaccess file. On Search Engine Watch it is recommended to use the below. I did block these bots in the robots.txt file but they are ignoring it.

Here is code from Search Engine Watch:

RewriteEngine on 
Options +FollowSymlinks 
RewriteBase / 
RewriteCond %{HTTP_USER_AGENT} ^Baiduspider [NC,OR” 
RewriteCond %{HTTP_USER_AGENT} ^Sogou
RewriteRule ^.*$ - [F”

My current htaccess file is as below. How exactly would I modify my current .htaccess with the above code? What do I add and where do I add the above? I assume some of the above is already included in my current htaccess file and does not need to be repeated.

Here is my current .htaccess:

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

   # END WordPress

Upvotes: 1

Views: 2178

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

Remove the Options line and just add them above your wordpress rules, and also change the to ]:

RewriteEngine on 
RewriteCond %{HTTP_USER_AGENT} ^Baiduspider [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Sogou [NC]
RewriteRule ^.*$ - [F]

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

# END WordPress

If you have other user agents you want to block, just add more conditions above the current ones:

RewriteCond %{HTTP_USER_AGENT} ^dont-want-this-string [NC,OR]

Upvotes: 4

Related Questions