| 1 | <h2>Comments</h2> |
| 2 | <pre><code># This is a comment |
| 3 | # <VirtualHost *:80> |
| 4 | </code></pre> |
| 5 | |
| 6 | <h2>Directives</h2> |
| 7 | <pre><code><Files .htaccess> |
| 8 | Order allow,deny |
| 9 | Deny from all |
| 10 | </Files> |
| 11 | </code></pre> |
| 12 | |
| 13 | <h2>Variables</h2> |
| 14 | <pre><code>RewriteCond %{REQUEST_FILENAME}.php -f</code></pre> |
| 15 | |
| 16 | <h2>Regex</h2> |
| 17 | <pre><code>^(.*)$ |
| 18 | !^www\.</code></pre> |
| 19 | |
| 20 | <h2>Directive flags</h2> |
| 21 | <pre><code>[NC] |
| 22 | [RC=301,L]</code></pre> |
| 23 | |
| 24 | <h2>Strings</h2> |
| 25 | <pre><code>AuthName "Fichiers réservés"</code></pre> |
| 26 | |
| 27 | <h2>Full example</h2> |
| 28 | <pre><code>## BASIC PASSWORD PROTECTION |
| 29 | AuthType basic |
| 30 | AuthName "prompt" |
| 31 | AuthUserFile /.htpasswd |
| 32 | AuthGroupFile /dev/null |
| 33 | Require valid-user |
| 34 | |
| 35 | ## ALLOW FROM IP OR VALID PASSWORD |
| 36 | Require valid-user |
| 37 | Allow from 192.168.1.23 |
| 38 | Satisfy Any |
| 39 | |
| 40 | ## PROTECT FILES |
| 41 | Order Allow,Deny |
| 42 | Deny from all |
| 43 | |
| 44 | ## REQUIRE SUBDOMAIN |
| 45 | RewriteCond %{HTTP_HOST} !^$ |
| 46 | RewriteCond %{HTTP_HOST} !^subdomain\.domain\.tld$ [NC] |
| 47 | RewriteRule ^/(.*)$ http://subdomain.domain.tld/$1 [L,R=301] |
| 48 | |
| 49 | ErrorDocument 403 http://www.example.com/logo.gif |
| 50 | ErrorDocument 403 /images/you_bad_hotlinker.gif |
| 51 | |
| 52 | ## REDIRECT UPLOADS |
| 53 | RewriteCond %{REQUEST_METHOD} ^(PUT|POST)$ [NC] |
| 54 | RewriteRule ^(.*)$ /cgi-bin/form-upload-processor.cgi?p=$1 [L,QSA]</code></pre> |