Apr
14
Block people from Certain URL Using htaccess
April 14, 2008 |
From time to time, you may ask yourself: How do I block people coming from a certain website or URL from visiting my site or directory?
It’s actually very similar to blocking people by IP! Again, you need to add some lines to an .htaccess text file that you create in the home directory of your web site.
Here is some example code for giving everybody who comes to you from www.yahoo.com or www.google.com a 403 error (access denied):
SetEnvIfNoCase Referer "^http://www.google.com/" BadReferrer
SetEnvIfNoCase Referer "^http://www.yahoo.com/" BadReferrer
order deny,allow
deny from env=BadReferrer
Another way to block people where you end up just redirecting them to a different url involves using the “mod_rewrite” functionality of our web server. Here’s how to block everybody from www.yahoo.com and www.google.com again (put this in your .htaccess file):
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://www.yahoo.com/
RewriteRule /* http://www.yoursite.com/restricted_url.html [R,L]
RewriteCond %{HTTP_REFERER} ^http://www.google.com/
RewriteRule /* http://www.yoursite.com/restricted_url.html [R,L]
We hope this helps keep those annoying people out of your site!
Similar Posts
- htaccess Deny Diractory Access During a Specific Time
- Block IPs Using htaccess
- Google Text Translation Using htaccess
- Use htaccess with Site Maintenance Page
- htaccess Remove the www From Domain URL
- Use htaccess to Deny Access Directory Listing
- htaccess Conditional Loop Redirect
- htaccess Require the www For Domain URL
- Use htaccess to Fake Different File Extension
- htaccess Explicitly Define Default Index File
- Remove File Extension Using htaccess
- Apache htaccess Prevent Users from Uploading and Executing Files
- htaccess Permanently redirect file or directory
- Create Custom Error Pages Using htaccess PHP
- Deny Access to inc Files Using htaccess
- Use htaccess for 404 Redirect
- Set Local Timezone Using htaccess
- Use htaccess to Deny Access to hidden Files
- htaccess gzip for Faster Loading and Bandwidth Saving
- Useful mod_rewrite Resources
- Force Files Like PDF Download using htaccess
- htaccess Limit the Number of Concurrent Visitors to your Website
Comments
1 Comment so far



































htaccess is really cool!