Standard .htaccess settings

There are plenty of resources out there to help give you a better understanding of .htaccess files and all the power they provide, but I find myself consistently creating the same file over and over.
I’m by no means an expert in server administration, apache, or .htaccess files, so use at your own risk!  If you think I’m missing something useful, or if something’s straight up wrong, let me know.
This basically keeps people out of your .htaccess files, frontpage extensions, etc…

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

Next setup a way to block malicious IP addresses.

order allow,deny
deny from XX.XX.XXX.XXX
allow from all

For SEO purposes, this sends a permanently moved 301 header to anyone accessing the site with a leading www. and redirects to the same resource requested, minus the www. There’s debate as to whether or not the www. should be included; personally I prefer no www., and there seems to be a consensus forming.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

Then, depending on your site / framework, you will likely want to combine additional mod_rewrite.c declarations.  So say I’m using CakePHP (as I often am), the complete .htaccess file looks something like this:

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

order allow,deny
deny from XX.XX.XXX.XXX
allow from all

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
    RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]