Knowledge base
1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Restricting access to certain pages in order to ban a visitor/robot/scraper
You can block access to specific directories for only specific visitors by filtering or blocking their IP addresses or host names.
Actions to be carried out
Create an .htaccess file inside /web containing the "Deny from" directive.Examples:
ErrorDocument 403 "Access denied"
Order Allow,Deny
Allow from allDeny from 62.75.221.104 # The IP address to deny
Deny from 192.170.0.2 # To deny access to IP address 192.170.0.2
Deny from 192.170 # to deny access to all IP addresses starting with 192.170
>Allow only certain IP addresses, where xxx.xxx.xxx.xxx are the IP addresses in question:
order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx
allow from xxx.xxx.xxx.xxx
allow from xxx.xxx.xxx.xxx
Block access to the unique IP address 123.45.6.7 and any IP starting with 012.34.5:
order allow,deny
deny from 123.45.6.7
deny from 012.34.5.
allow from all
Use mod_rewrite:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^62.75.221.104
RewriteCond %{REMOTE_ADDR} ^62.75.221.[0-9]
RewriteRule .* - [F,L]
You can also use the following code if you wish all visitors to site "domain.xyz" to be redirected to "www.perdu.com" whenever they reference an element from your site:/strong>
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-|.)domaine.xyz(-|.).*$ [NC]
RewriteRule .* http://www.perdu.com/ [R,L]
Also read this FAQ (click here).