Frank Jance

Member
Jan 13, 2018
8
0
1
USA
cPanel Access Level
Root Administrator
I'm trying to set up deflector maps in httpd.conf to reroute bots based on agent and IP address. I entered the following code (Pre Main Include - all versions) in the Service Configuration » Apache Configuration » Include Editor:

RewriteEngine on
RewriteMap deflector txt:/home/user/maps/deflector_agent.map
RewriteCond %{HTTP_REFERER} !=""
RewriteCond ${deflector:%{HTTP_REFERER}} =-
RewriteRule ^ %{HTTP_REFERER} [R,L]

RewriteCond %{HTTP_REFERER} !=""
RewriteCond ${deflector:%{HTTP_REFERER}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^ ${deflector:%{HTTP_REFERER}} [R,L]

RewriteEngine on
RewriteMap ip-deny txt:/home/user/maps/deflector_ip.map
RewriteCond ${ip-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^ - [F]

However, this doesn't seem to be working. I entered my IP in the deflector_ip.map file but I'm not blocked from my site. What am I doing wrong?

Thanks,
Frank
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
Hello Frank,

You may want to add the entries as a virtual host include for all virtual hosts instead of a "Pre Main Include". Here's a thread where this is discussed (it's for different entries but the same principal applies):

SOLVED - Auto Force TLS

Thank you.
 

Frank Jance

Member
Jan 13, 2018
8
0
1
USA
cPanel Access Level
Root Administrator
Thanks, Michael. I tried both Pre VirtualHost Include and Post VirtualHost Include, but neither of those worked for me either. Is it because I'm using LiteSpeed instead of Apache? Or do I need more code to get what I've written to be recognized? The code I posted should work, as I copied it almost verbatim from the Apache website.

I usually add these things to .htaccess, however this particular solution won't work there and is required to go in httpd.conf.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463

Frank Jance

Member
Jan 13, 2018
8
0
1
USA
cPanel Access Level
Root Administrator
For the life of me, I still can't figure this out. Does anyone have an example of how to set up a deflector map on httpd? There are plenty of examples on how to create the map, but absolutely nothing on how to set up RewriteMap in the conf file.

Thanks.