IIS htaccess rule converter only importing 1 rule

2020-05-07 06:26发布

问题:

I have a example .htaccess file (found here) with bad robots to block. Here's a small sample code block from that file:

#bad bots start
#programmed by tab-studio.com public  version 2017.12
#1 new rule every 500 entries
RewriteCond %{HTTP_USER_AGENT} \
12soso|\
192\.comagent|\
1noonbot|\
zuibot|\
zyborg|\
zyte\
 [NC]
RewriteRule .* - [F]
#bad bots end

Basically throwing a 403 on a URL match. I checked this post to see how I can convert these .htaccess rules to a web.config rewrite rule via IIS. When I import the rules however, I get an unexpected result where no rules seem to be converted, see image below. What am I doing wrong?

回答1:

It's certainly choking on the \ and the carriage return. If you try the following you'll see it should import properly:

#bad bots start
#programmed by tab-studio.com public  version 2017.12
#1 new rule every 500 entries
RewriteCond %{HTTP_USER_AGENT} 12soso|192\.comagent|1noonbot|zuibot|zyborg|zyte
 [NC]
RewriteRule .* - [F]
#bad bots end

Having said that, you might consider looking at using Request Filtering & Scan Headers instead: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/filteringrules/filteringrule/scanheaders/