Current Customers > .htaccess

.htaccess

  1. How do I password protect a folder or directory on my site?
  2. How do I make custom 404, 403, etc, error pages?
  3. Can I block certain IP addresses from accessing my site?
  4. How can I stop people from hotlinking to my site?


1. How do I password protect a folder or directory on my site?

Using NOTEPAD or another text editor, create a file called ".htaccess" which contains the following lines:

AuthType Basic
AuthName "Secure Area"
AuthUserFile /htdocs/<username>/<domain>/<dir>/.htpasswd

<Limit GET PUT POST>
require valid-user
</Limit>

You will of course need to replace <username> with your username, <domain> with a domain name that is hosted by us, and <dir> with the name of the folder/directory you are attempting to password protect. The ".htaccess" file must be placed INSIDE of the folder/directory you will be protecting.

In order for surfers to be able to access this part of your site, you must create a second file called ".htpasswd" which contains the usernames/passwords. This file must be placed in the folder your are protecting (as shown above in the AuthUserFile line). By using our Password Generation Tool, you can create accounts and paste them into your ".htpasswd" file.

Back To Top

 

2. How do I make custom 404, 403, etc, error pages?

First, create the HTML page which will replace the standard Apache error message (for example: 404.html, 403.html, etc). If you haven't already created an .htaccess file, open a text editor, such as NOTEPAD, and create a file called ".htaccess".

For each error you wish to customize, add a line to your ".htaccess" File:

ErrorDocument 404 /404.html

NOTE: The path to the file may vary slightly if you've put the 404.html file in a different folder/directory.

The table below shows common server status codes and when they might occur.

Status Code Error Occurrence
401 Authorization Required Invalid username/password entered
403 Forbidden Visitors are blocked from viewing directory contents
404 File Not Found File missing
Back To Top

 

3. Can I block certain IP addresses from accessing my site?

Using NOTEPAD or another text editor, create a file called ".htaccess" which contains the following lines:

<Limit GET PUT POST>
order deny,allow
deny from 192.0.0.1
</Limit>

NOTE: Replace the IP address above (192.0.0.1) with the IP you'd like to block.

Back To Top

 

4. How can I stop people from hotlinking to my site?

The site below has a short, helpful tutorial on the subject.
http://faq.solutionscripts.com/misc/hot_linking.html

Back To Top