Sometimes it is necessary to restrict access to your website wether its for development purposes or to block certain IP addresses e.g bots / hackers. To do this you need to create a htaccess file and place it in the folder you wish to protect. For example if you wish to restrict access to the entire website, you would place the htaccess file in your root web folder , in our example below this would be the httpdocs folder.
- Login to your client area http://ca.myhost.ie and click on Services > My Services and click the drop down menu opposite the service you want to access and click Open Control Panel
- If you have a multiple webspace subscription click the Webspaces tab and select the webspace you want to modify . If the webspace tab does not exist then go ahead and click on the FILES option from the Menu.
- You will see a top down layout of your web folders. Select the HTTPDOCS folder or if you have more than one domain , choose the appropriate site folder where the website files are stored.
- If the htaccess file does not already exist, from the new menu that appears click New > File and enter the file name .htaccess and click OK . Its important to put the . before the filename to make it executable.
- Now you should have a file called .htaccess in the root folder of your website.
- Next we have to edit this file, hover your mouse pointer over this file and a drop down menu arrow appears , click it and choose Edit In Text Editor.
- The contents of the .htaccess file will open.If the .htaccess file previously existed look for an entry called order allow,deny and a list of deny from <ip_address> entries below it. This is where you will add the IP address you wish to prevent from accessing your website e.g deny from XXX.XXX.XXX.XXX so anyone trying to visit your website from this IP address will be restricted. See example below
To block visitors to your site from specified ip addresses use the following syntax:
# Access rules
order allow,deny
deny from XXX.XXX.XXX.XXX
allow from all
To block all visitors to your site but for the specified ip's use the following syntax:
# Access rules
order deny,allow
allow from XXX.XXX.XXX.XXX
deny from all
Above is just an example but once you are happy the entries are added you can click the OK button to apply the changes.