Htaccess    html   Php   javascript   Asp   css    maths  Past Questions

Htaccess guide & tricks Donate at flattr Flattr this





Alert! Connect with 10,000 Chating Online. Join Now

IP Blocking


There are times when we need to deny some ips from accessing our page or we need to block a user or region from accessing our site.

A quick way of temporarily stopping people from accessing your site is to block them by IP. To block people/computers with certain IPs from accessing your site, you can use the following command format:

order allow,deny

deny from 192.52.0.3

deny from 134.112.156

deny from 128.32.4.78

deny from 60.32

allow from all

To implemenrtt this on your site, just copy the code above and put it in your htaccess file and replace the ip address with the ones you want to block. if you want to block an ip range say for example you want to block all people in an entire country, you will only need to enter a small portion of their IP such as 60.32. All IPs that begin with 60.32 such as 60.32.135.3 and 60.32.132.122 will also be blocked automatically. you can block as many individual ips by add as many deny from lines of code as you want.

Allowing Only a Certain IPs



If you want to only allow a certain IP range to access your site or page eg a paid user to a section of your site, you can use allow from lines just like in the blocking above: order allow,deny allow from 123.456.789.012 deny from all Allowing only a certain IP should be used only for special situation, for you never know when your IP address may change. If you do control the IP address such as on your own private network or intranet, go all out with this setting if you don't have a better way of restricting access.

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. This can be useful to restrict a spammer, hacker or disgruntled member attacking your site.

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 153.45.6.8

deny from 87.65.4.7

deny from 78.45.34.34

allow from all


What is a .htaccess File?

Custom Error Pages

IP Blocking

Change Non WWW URLs to WWW URLs

Turning On Compression using GZIP

SEO 301 Redirect

Change the Default Directory Page/index file

How to Stop Directory Listing

How to stop someone looking at your htaccess file

Password Protect a Directory

Control access at files & directory level

Modifying the Environment Variable

Implementing server Caching Scheme with .htaccess

Redirect browser to https (ssl)

Rewrite URLs using htacccess

Adding new MIME types)

Specify Upload file limit for PHP in htaccess

Disallow Script Execution

Change Charset and Language headers

Set Timezone of the Server (GMT)

Force "File Save As" Prompt and File download

Protecting a single file

Set Cookie using htaccess

Send Custom Headers

Blocking request based on User-Agent Header

Disable caching for certain file type

Hotlinking protection with .htaccess

Prevent hacks

Disable directory browsing

Rename .htaccess files to another filename

Change default Index page

Block unwanted visitor based on referring domain

Secure directories by disabling execution of scripts

All the tutorials on this site are free, you can copy and print the tutorials and code on this site, but you are not allowed to reproduce this information on another website.
 
 
Htaccess    html   Php   javascript   Asp   css    maths  Past Questions