Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 613993 of .htaccess ( hypertext access )

  • Revision slug: Sample_.htaccess_file
  • Revision title: .htaccess ( hypertext access )
  • Revision id: 613993
  • Created:
  • Creator: anushbmx
  • Is current revision? No
  • Comment Fixes Gramatical Error in "File Accessing" section

Revision Content

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 / https://example.com/       # redirect the traffic to the directory to example.com , Permanent Redirect
Redirect 302 / https://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 notfound.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.

Revision Source

<p>The term .htaccess stands for "hypertext access".&nbsp;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 &amp; redirects, and more.</p>
<p><strong>File Accessing</strong> : htaccess&nbsp;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.</p>
<h2 id="Common_Application">Common Application</h2>
<p><strong>URL&nbsp;Redirects &amp;&nbsp;rewrite</strong>: 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&nbsp;by supplying&nbsp;the status codes.</p>
<pre>
Redirect 301 / https://example.com/       # redirect the traffic to the directory to example.com , Permanent&nbsp;Redirect
Redirect 302 / https://example.com/       # redirect the traffic to the directory to example.com , Temporary&nbsp;Redirect
</pre>
<p><strong>Blocking </strong>: htaccess also facilitates blocking traffic based on IP and IP range,&nbsp;&nbsp;Also, use to block bad bots, rippers, and referrers; often used to restrict access by Search Engine spiders.</p>
<pre>
deny from 146.0.74.205                   # Blocks all access from 146.0.74.205 to the directory</pre>
<p><strong>SSI or Server Side Include</strong> : 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.</p>
<pre>
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
</pre>
<p><strong>Customized error responses :</strong> User can be directed to different pages depending on the Error they caused or by the webserver.</p>
<pre>
ErrorDocument 404 /notfound.html # Redirects traffic to notfound.html in case of a 404 error
ErrorDocument 500 /serverr.html &nbsp;&nbsp; # Redirects traffic to notfound.html in case of a 500 internal server error
</pre>
<p>For further information see this external article: <a href="https://techstream.org/Web-Development/HTACCESS/Error-Documents">Redirect your Traffic for Error Handling</a>.</p>
<p><strong>Cache Control :&nbsp;</strong><span style="line-height: 1.572;">.htaccess allows a server to control caching by web browsers, helps load pages faster, and reduces the data transfer.</span></p>
<p><strong>MIME types</strong>&nbsp;: see&nbsp;<a href="/en-US/docs/Properly_Configuring_Server_MIME_Types" title="Properly_Configuring_Server_MIME_Types">correct MIME types</a>&nbsp;for further information.</p>
Revert to this revision