basic .htaccess template

by prettyscripts on 2011-02-25 14:18

code

.htaccess is a text file containing commands to control an entire website. i can never remember details what to put inside. this is just a basic template / skeleton for my web projects, so that i don't have to go all over places to look for what i want everytime i start a new project.

Code

Options +FollowSymLinks
IndexIgnore *
ServerSignature Off
 
<Limit GET POST PUT>
    order allow, deny
    allow from all
    #deny from x.x.x.x
</Limit>
 
<Files .htaccess>
    order allow,deny
    deny from all
</Files>
 
<IfModule mod_rewrite.c>
    RewriteEngine On
 
    #ErrorDocument 404 /errors/404.php
    #ErrorDocument 403 /errors/403.php
 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)$ index.php
</IfModule>

notes

line 1: follow symbolic links. useful when i just link most frequently used files without having multiple copies everywhere.

line 2: do not allow directory listing, so that the world doesn't see your files.

line 8: block ip addresses from accessing your website.

lines 11-14: prevent people from viewing your .htaccess file.

lines 19-20: customized error pages.

lines 22-23: use directory or file if they exists

line 25: everything else, forward to index.php.