Apache >
This was an absolute nightmare and one of the main reasons I started to hate hosting things myself.
See also:
Notes ∞
NC- No CaseL- Last rule-
redirectpermanent /foo/index.html http://subdomain.example.com
Security ∞
See also:
Stop hotlinking ∞
# Stop hotlinking
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
# multiple URLs are possible..
RewriteCond %{HTTP_REFERER} !^http://example.com [NC]
RewriteRule .*\.(gif|jpg|png|swf)$ - [NC,F]
# I could also redirect them to something else:
# RewriteRule \.(gif|jpg|png|swf)$ http://example.com/no_hotlinking.jpg [R,L]
IP Banning ∞
Another solution exists in .htaccess
See also Bad Behavior and MediaWiki security.
IP Banning with mod_rewrite ∞
RewriteCond %{HTTP_REFERER} ^http://(www\.)?([a-z0-9\-]+)\.blogspot\.com(/)? [NC]
using an external file ∞
So instead of needing to restart the server every time there is a change, have an external document referred to:
# Block IPs and hostnames using an external configuration file:
RewriteMap hosts-deny txt:/opt/lampp/mediawiki/hosts_deny.map.txt
RewriteCond ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND [OR]
RewriteCond ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^/.* - [F]
For example, under winblows you could use something like `C:/xampplite/mediawiki/hosts_deny.map.txt
The contents of this hosts_deny.map.txt file could be something like:
# use the regular URLs, dumbass. =) 127.0.0.1 - localhost -
-
TODO - Can this do ranges?
Bouncing referrers ∞
# Selectively bounce or redirect certain referrers, dynamically with an external file:
RewriteMap bounce txt:path/to/referrer_bounce.map.txt
RewriteCond %{HTTP_REFERER} !=""
RewriteCond ${bounce:%{HTTP_REFERER}} ^-$
RewriteRule ^.* %{HTTP_REFERER} [R,L]
RewriteCond %{HTTP_REFERER} !=""
RewriteCond ${bounce:%{HTTP_REFERER}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^.* ${bounce:%{HTTP_REFERER}} [R,L]
For example, under Windows you could use something like C:/xampplite/mediawiki/referrer_bounce.map.txt
The contents of this referrer_bounce.map.txt file could be something like:
http://www.example.com/bad/index.html - http://www.example.com/bad/index2.html https://spiralofhope.com/
Last updated 2020-05-15 at 13:21:22

Pulled from the main Apache topic and cleaned up.
ported