When we want to block bots, spam referrers using .htaccess file, some websites use following code syntax:
Order allow,deny
Allow from all
Deny from env=spambot
But some websites tell that we need to use different codes for different Apache versions:
#For Apache 2.2
<IfModule !mod_authz_core.c>
<IfModule mod_authz_host.c>
Order allow,deny
Allow from all
Deny from env=spambot
</IfModule>
</IfModule>
# For Apache 2.4
<IfModule mod_authz_core.c>
<RequireAll>
Require all granted
Require not env spambot
</RequireAll>
</IfModule>
Now I want to which cone is correct or both are correct?
spambotwould need to be defined somewhere. However, you wouldn't normally use both... you would just use the appropriate directives for your server version. Unless this code is intended to work on both servers? Any new server should be using Apache 2.4 these days, if not it should be upgraded. – MrWhite Aug 28 '17 at 14:37SetEnvIfNoCase Referer spamdomain\.com spambot=yesline.I checked and my Apache version is Apache/2.4.23 (Unix), so should I use the code given after
# For Apache 2.4line? Is it fine to use?Again if I keep both codes
– Aug 28 '17 at 15:20#For Apache 2.2and#For Apache 2.4, will it not work? Will it cause any issues?<IfModule>wrappers. Maintaining additional code when you don't need it is just additional work (and more chance for error). – MrWhite Aug 28 '17 at 15:37<RequireAll> Require all granted Require not env spambot </RequireAll>line without<IfModule mod_authz_core.c>line? Also is<RequireAll></RequireAll>tag is necessary? – Aug 28 '17 at 15:40RewriteCond %{HTTP_REFERER} domain\.com [NC], my website was showing 403 forbidden page to blocked referrer successfully. – Aug 28 '17 at 18:13<RequireAll>container is required in this example, otherwise<RequireAny>will be implied and access will be granted unconditionally. That code should do as you say, "show 403 forbidden page to users which come from the blocked referrer". In fact, this would be preferable to using mod_rewrite, which could conflict (and be overridden) with other directives/.htaccessfiles. – MrWhite Aug 28 '17 at 23:39SetEnvIfNoCasemethod is not working for me. I'm checking with a Chrome extension which allows us to use custom referrer and if I usemod_rewritemethod, Chrome shows 403 forbidden error page but if I useSetEnvIfNoCasemethod, my webpage opens normally. What thing am I doing wrong? – Aug 29 '17 at 06:22.htaccesscode. Is this all in.htaccess, or do you have access to the server config? – MrWhite Aug 29 '17 at 07:16SetEnvIfNoCasecode but still same issue. I have uploaded the code of my .htaccess file at following link:link
– Aug 29 '17 at 07:35link
– Aug 29 '17 at 08:13