Apache .htaccess

From HaFrWiki
Revision as of 17:13, 1 October 2018 by Hjmf (talk | contribs) (Created page with "{{TOCright}} The Apache Webserver file <code>.htaccess</code> is a powerful tool for managing the access and navigation to your webserver. <br>Unfortunately, the working is no...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Apache Webserver file .htaccess is a powerful tool for managing the access and navigation to your webserver.
Unfortunately, the working is not very intuitive and not very simple.

Examples

Prevent PHP-Directory Access

The usage of a special PHP-include directory is a common implementation paradigm.
But you don't want anyone to have access to that directory except the program/application. This snippet prevents the access to the directory file with extension php. <syntaxhighlight lang="bash">

    1. Enable Mod Rewrite, this is only required once in each .htaccess file

RewriteEngine On RewriteBase /

    1. Test for access to the include directory

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /phpinclude/.*$ [NC]

    1. Test that file requested has php extension

RewriteCond %{REQUEST_FILENAME} ^.+\.php$

    1. Forbid Access

RewriteRule .* - [F,NS,L]

</syntaxhighlight>

See also

top

Reference

top