.htaccess files are special files that contain instructions for the web server software, generally used to limit access to a file or directory, add content-types, or perform URL rewriting or simple redirection. The file is a plain text configuration file created locally on your computer, named ".htaccess" (with the preceding period), then uploaded into the directory that you wish to have the file operate on. Please note that the file MUST be plain text, not an HTML or word processor (Microsoft Office, OpenOffice, RTF) document. We suggest using the utility "NotePad" on Windows or "TextEdit" on the Mac to create these files.
Access Control with .htaccess
By default, all files uploaded to hosting web space are available to be downloaded without the need to enter a username or password (unless permissions are changed or the files are behind a content-management system). If you need to restrict access, this is generally accomplished through the use .htaccess files. To restrict access to a particular directory, you will first need to upload a .htaccess file containing the following statements:
AuthUserFile /WWW/example.com/.htpasswd AuthName "Password Protected" AuthType Basic require valid-user
Note that the path has been changed for our newer hosting servers hosting8+. For newer servers you must use:
The first directive (AuthUserFile) states where the password file is located on the server. Note that on servers hosting8 and newer, you cannot write to the top level of the web directory. The second (AuthUserName) specifies a name for the resource, which shows in most browsers' password dialog boxes. The third directive, AuthType, should always be 'Basic' -- which simply reads encrypted passwords from the .htpasswd file. Finally, the last directive tells the server to allow users in if they match any account/password in the .htpasswd file. You will now need to create an upload a .htpasswd file, in the following format:
The first field is the username used to gain access. The second is an encrypted password for that account. In order to create the .htpasswd file properly (including encrypting the passwords), use of an automated tool is suggested. One is available at: http://www.clockwatchers.com/htaccess_tool.html. Please note that this tool is provided by a third party, and visp.net neither supports it nor endorses its use.
Website Redirection with .htaccess
In its default configuration, the web server software will serve up pages from your website's home directory (such as "/WWW/example.com"); with redirection, you can tell the server to send a "Redirect" command to the browser, which the browser then automatically follows to a different page. Redirection can be useful if you've changed your website layout and wish to capture visits to old pages, perhaps from bookmarks or stale search engine data. To do this, simply add to your .htaccess file:
Redirect 301 /oldpage.html http://www.example.com/newpage.html
Be sure to include full subdirectories for files as part of the path, if needed:
Redirect 301 /data/oldpage.html http://www.example.com/data/newpage.html
Redirection is also handy if you've got your email services hosted here but main website hosted elsewhere. Provided DNS is set up properly, the following will redirect visitors to "example.com" to the host "www.example.com", which may be another webhost where the site is located:
Redirect 301 / http://www.example.com