Rewrite rules (.htaccess) not working as per examples

#1
Hi all

As per this page >https://openlitespeed.org/kb/access-control/

Code:
RewriteCond %{HTTP_USER_AGENT} !.*google.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !.*Bing.* [NC]
RewriteRule sitemap.xml$ - [F,L]
This rewrite rules block everything, even if I pass google as a referrer it doesn't work, literally the entire web site responds with 403
I am finding such a simple thing as rewrites to be awfully complicated which is rather troubling.
 

Cold-Egg

Administrator
#2
Thanks for the report.
Both

Code:
RewriteCond %{HTTP_USER_AGENT} !.*google.* [NC]
RewriteCond %{HTTP_USER_AGENT} !.*Bing.* [NC]
RewriteRule sitemap.xml$ - [F,L]
and

Code:
RewriteCond %{HTTP_USER_AGENT} !.*(google|Bing).* [NC]
RewriteRule sitemap.xml$ - [F,L]
Should works.
 
#3
Thanks @Cold-Egg I did resolve this and tried to edit my post but it had not been approved yet.

For others who find this post. I was adding the rules between

Code:
<IfModule mod_rewrite.c>
</IfModule>
instead I found it had to be between

Code:
<IfModule LiteSpeed>
</IfModule>
For anyone seeking a solution to blocking Bad User-Agents and Spam Referrers (seen many post about it) I have a fully working Openlitespeed version of my Bot Blocker project at github.com/mitchellkrogza/apache-ultimate-bad-bot-blocker/blob/master/OpenLitespeed_htaccess/
 
Top