post your comment   print   send to a friend
Rate:   0% | Views: 1114
Question categories:  Unix Plans

Can I use .htaccess file to block traffic from specific IP addresses?

Answer by: Andrew Hickl, Aplus.Net Knowledge Base Support.

.htaccess files can be used to block traffic from specific IP addresses that may be trying accessing your site maliciously.

Here’s how to do it:

  1. Start by editing the .htaccess file in the directory you’re looking to customize.  (We recommend editing it using the “Edit” function found in the File Manager on the Control Panel.)  If you currently do not have a .htaccess file, create one locally using a text editor like NotePad (Windows), SimpleText (Macintosh) or Emacs (Linux / UNIX).
 
  1. Next, enter the following code into your .htaccess file:

order allow,deny

deny from domain.com

allow from domain.com

You will need to replace ‘domain.com’ in the code above with either the IP address or the domain name of the site(s) that you want to grant or deny access to your site. If you’re granting / denying access to several individual sites, you’ll need to make each request on an individual line, as in the following example:

order allow,deny

deny from 216.55.129.46

deny from aplus.net

allow from 66.83.239.66

allow from apluskb.com


In order to grant / deny access to all users, simply replace ‘domain.com’ in the above examples with the word ‘all’.  For example:

order allow,deny

deny from apluskb.com

allow from all

In the example above, traffic from originating at http://apluskb.com is blocked, but all other traffic is permitted.

  1. Save your .htaccess file to your local computer.

  2. Open your FTP client and establish a connection to your web space using your FTP Username and FTP Password.  Your connection URL should be www.yourdomainname.com (where ‘yourdomainname.com’ = the actual name of your domain).
  1. Browse to the directory that you’d like to customize.

  2. Set your upload settings to ASCII.  (Uploading .htaccess files in ‘binary’ format may have unexpected consequences.)

  3. Upload your .htaccess file from your local computer.

  4. After the upload is completed, you may need to change the file permissions for the .htaccess file.  They should be set to 644 (using chmod) or RW-R--R--.

Note: If you have a Windows-based hosting plan, you cannot use .htaccess files.

Customer Feedback
Rate:   0% | Views: 1114 | Please Rate:  
 
If you have other comments or ideas for future technical tips, please type them here:

Email: (optional)

Comments: (optional)

 Domain Name Registration | Increase Website Traffic    Back to serch results
Browse the Base
Knowledge Base
Shared Hosting
  Unix Plans
    MySQL
Messages
 

$75 Free Google AdWords

Free $75 Google AdWords when you sign up for WebImage! Target by location, create your own, or let Google create your ads for you. Check out http://www.aplus.net/google.html to see how AdWords works for you.

Private Area
 
Ask
in Private
   
Personal
Folder
 
Related Questions
 
1. I have a Unix-based shared hosting plan. How can I change permissions for files/directories using the File Manager?
 
2. How can I protect directories?
 
3. How to Set Up a Storefront ?
 
4. What are the permissions on files and directories?
 
5. In Unix, what is the find command, and how do I use it to search through directories for files?
 
Home Browse Search Ask in Private Personal Folder   Help
powered by web hosting 
  Logged as: Guest