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 479243 of .htaccess ( hypertext access )

  • Revision slug: Sample_.htaccess_file
  • Revision title: .htaccess ( hypertext access )
  • Revision id: 479243
  • Created:
  • Creator: anushbmx
  • Is current revision? No
  • Comment

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.

Editor : .htaccess files can be opened with Apache Web Server or any text editor, like Windows Notepad or Vim etc.

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 fast and efficient way of redirecting traffic, because the redirect happpens before the pages are served. Redirects can be made on temporary basic 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 wither 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 trafics to notfound.html in case of a 404 error
ErrorDocument 500 /serverr.html    # Redirects trafics to notfound.html in case of 500 internal server error

Further information see this external aricle Redirect your Traffic for Error handeling.

Cache Control : .htaccess allow 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>Editor</strong> :&nbsp;.htaccess&nbsp;files can be opened with Apache Web Server or any text editor, like Windows Notepad or Vim etc.</p>
<h2>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 fast and efficient way of redirecting traffic, because the redirect happpens before the pages are served. Redirects can be made on temporary basic 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, &nbsp;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,&nbsp;you can have them automatically attached to all the files wither at top or bottom automatically through your .htaccess file.</p>
<pre>
</pre>
<div>
  php_value auto_prepend_file "/real/path/to/file/functions.php" # Adds function.php at the top of requested document</div>
<div>
  php_value auto_append_file "/real/path/to/file/footer.php" # Adds footer.html at bottom of requested document</div>
<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>
</pre>
<div>
  ErrorDocument 404 /notfound.html # Redirects trafics to notfound.html in case of a 404 error</div>
<div>
  ErrorDocument 500 /serverr.html &nbsp;&nbsp; # Redirects trafics to notfound.html in case of 500 internal server error</div>
<p>Further information see this external aricle&nbsp;<a href="https://techstream.org/Web-Development/HTACCESS/Error-Documents">Redirect your Traffic for Error handeling</a>.</p>
<p><strong>Cache Control :&nbsp;</strong><span style="line-height: 1.572;">.htaccess allow 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