Social Icons

Monday, July 22, 2013

Deny a user by IP Address & How to stop someone looking at your htaccess file

1.Deny a user by IP Address
There may come a time when you unfortunately need to ban someone from visiting your website completely. This is very easy to do using htaccess and can be useful if there is a spammer or disgruntled member attacking your site (something which unfortunately happens a lot to forum and blog owners).
To ban someone completely all you need to do is add the following code to your .htaccess file. Simply replace the ip address below with the ip of the person you want to ban
#ban users from visiting the site
order allow,deny
deny from 123.45.6.7
allow from all
If you want to ban more people you simply add more lines, like this :
#ban users from visiting the site
order allow,deny
deny from 123.45.6.7
deny from 987.65.4.3
deny from 56.45.34.456
allow from all


2.How to stop someone looking at your htaccess file
One of the first things you want to do is make sure no one tries to look at your .htaccess file. This is actually very easy to do, all you need to do is make use of the Files option.

Just enter the code below to block people seeing your .htaccess file.

# Block people seeing the htaccess file
<Files .htaccess>
order deny,allow
deny from all
</Files>
If there is no .htaccess file there then you need to create one. Thankfully, this is very easy to do. All you need to do is open a text editor and save a blank document as .htaccess. Save the file exactly as it is stated there in bold ie. there is no writing before the extension. You need to save it as .htaccessand not htaccess.txt or document1.htaccess or whatever.

When uploading you should always :
  • Upload in ASCII mode, not binary
  • CHMOD the file to 644 (this isn’t absolutely necessary per say but it’s advisable, it means your server can access it but it can’t be seen via a browser).


Also, after editing your .htaccess file serveral times it may look a little complicated so I recommend adding a comment above the longer parts of code so that you know what each section is for when you look at the file again at a later date. To add a comment to the file you simply start the line with #, any code written after the # in the line will not be executed and is simply a reference for you in the future (and anyone else who may be working on your website ie. co-admin or whatever).

No comments: