Block or limit access to website by ip address
This is one of the fastest ways to block access to your entire online website. It is very usefull when you are working for a client who wants to see the progress of their website live anytime, without it being public. Just add your ip address so you can work on it and then theirs. The downside, is that if you don’t have a fixed ip address, you will have to update the ip address just as often. Another option(for longer term) is to put a password using .htpasswd which I will post about soon. It takes some configuration at first but is pretty simple once you’ve gotten the first one working on your server. Once you have added these lines to your .htaccess file, this is what other people who tries to acess your website sees. You can also make a 403.html template if you want them to see something pretty like coming soon with countdown or whatever.
*If you do not know how to make a .htaccess file, please read below for more about htaccess files
#allow acces to only one ip adress order deny,allow deny from all allow from xx.xx.xx.xxx #allow access to mulitple ip adresses by just adding more allow lines order deny,allow deny from all allow from xx.xx.xx.xxx allow from xx.xx.xx.xxx #allow access to all but block a few ip adresses by just adding more deny lines order allow,deny allow from all deny from xx.xx.xx.xxx deny from xx.xx.xx.xxx #or deny from xx.xx.xx.xxx xx.xx.xx.xxx
*To create an htaccess file you only need a text editor that does not force a pre-defined file extension. Create a new file and name it .htaccess
Create the file at the root of your website or folder which you want to block access. Beware that putting it at the root of your server can affect ALL the websites on your server, so be careful. Once you have created your file, you can start writing in it. If it disappears after being created, just make hidden files visible and you will see it. The file does no damage/modifications to your code or folders. It is accessed first when people access your server and can be considered as a user-server(files) filter. You can comment lines with # or delete lines in the file for it to have no effect. An htaccess file is very useful for php website programmers because it allows you to modify page links. For example, no more about.php or contact.html in the browser link, but /about or /contact instead. I’ll write more about url rewritting in a different post.