mozilla

.htaccess ( hypertext access )

The term .htaccess stands for "hypertext access". A file with the HTACCESS file extension is an Access Configuration file for apache server. The .htaccess file configures the current directory with things like password protection, URL rewrites & redirects, and more.

File Accessing : htaccess files can be opened using any text editor, like Windows Notepad, Vin, Sublime text editor or any other. Syntax highliting support for .htaccess files less.

Common Application

URL Redirects & rewrite: htaccess files are often used to redirect traffic to a web page to another or from traffic to a directory to another even between domains is possible. It's a fast and efficient way of redirecting traffic, because the redirect happens before the pages are served. Redirects can be made on a temporary basis or permanently by supplying the status codes.

Redirect 301 / http://example.com/       # redirect the traffic to the directory to example.com , Permanent Redirect
Redirect 302 / http://example.com/       # redirect the traffic to the directory to example.com , Temporary Redirect

Blocking : htaccess also facilitates blocking traffic based on IP and IP range,  Also, use to block bad bots, rippers, and referrers; often used to restrict access by Search Engine spiders.

deny from 146.0.74.205                   # Blocks all access from 146.0.74.205 to the directory

SSI or Server Side Include : Include external files to each file requested by the user without the need to write include statements in the file; you can have them automatically attached to all the files, whether at top or bottom, automatically through your .htaccess file.

php_value auto_prepend_file "/real/path/to/file/functions.php" # Adds function.php at the top of requested document
php_value auto_append_file "/real/path/to/file/footer.php" # Adds footer.html at bottom of requested document

Customized error responses : User can be directed to different pages depending on the Error they caused or by the webserver.

ErrorDocument 404 /notfound.html # Redirects traffic to notfound.html in case of a 404 error
ErrorDocument 500 /serverr.html  # Redirects traffic to serverr.html in case of a 500 internal server error

For further information see this external article: Redirect your Traffic for Error Handling.

Cache Control : .htaccess allows a server to control caching by web browsers, helps load pages faster, and reduces the data transfer.

MIME types : see correct MIME types for further information.

Document Tags and Contributors

Last updated by: VldSh,