.htaccess (Hypertext Access) is the default name of Apache's directory-level configuration file. It provides the ability to customize configuration directives defined in Apache's main configuration file, to modify the access to and behavior of certain directories on our web server.

Creating .htaccess files

It's important that you use a text editor which does not place carriage returns at the end of lines, as these can cause problems when Apache is trying to read the files. Almost every text editor on Windows will stick these carriage returns in, so we recommend you SSH into and create your file with one of the many editors installed on the server, such as emacs, vi, pico, or nano.

Password-protecting directories

The most common reason for using a .htaccess file is to restrict access to a directory.

Restrict access to users on campus

order deny,allow
deny from all
allow from 138.236.

Restrict access to specific user(s)

Restrict access to specific LDAP group(s)


If an entire directory has moved permanently, the smoothest and most efficient way to redirect visitors is using a 301 redirect:

Redirect 301 /relative/source

URLs with spaces

Although URLs should never contain spaces, if you happen to be redirecting either to or from a URL that has a space in it, use quotation marks:

Redirect 301 "/relative/source with spaces"

Forcing HTTPS

This method requires mod_rewrite.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

External link