Prettyscripts

Basic .htaccess Template

.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.

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 can’t see your files and directory structure
  • 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.

2 comments

  • Veikko Lehtinen

    Thank you so much! I had problems getting the forwarding to index.php working it kept forwarding me to my host’s ‘Forbidden’ page which was very annoying, searched a lot on Google and found this. Helped me a lot and got my site working again. :) Thank you again. Not a big deal to anyone than me though, I’m just practicing. Made me very happy to success.

Leave a Reply