#This sample file provided by Shannon Smith of Cafe Noir Design
#under the GPL. This file is provided as a learning tool, as is,
#with no warranty of any kind. Use this file at your own risk.
#allow redirects
Options +FollowSymlinks
RewriteEngine on
#redirect non-www urls
######################################################
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
#redirect www urls
######################################################
#rewritecond %{HTTP_HOST} !^www\.
#rewriterule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#redirect other domain names
######################################################
RewriteCond %{HTTP_HOST} ^example.ca [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
RewriteCond %{HTTP_HOST} ^www.example.ca [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
#redirect a single page permanently
######################################################
Redirect 301 /old.html http://www.example.com/new.html
#redirect a single page temporarily
######################################################
Redirect 302 /old.html http://www.example.com/new.html
#redirect to a maintenance page temporarily
######################################################
#RedirectMatch 302 ^/ /maintenancepage.html
# redirect all visitors to alternate site but retain full access for you
#ErrorDocument 403 http://www.alternate-site.com
#Order deny,allow
#Deny from all
#Allow from 99.88.77.66
#disable directory browsing
######################################################
Options -indexes
# disable the server signature
######################################################
ServerSignature Off
#block bad sites
######################################################
RewriteCond %{HTTP_REFERER} badbadsite\.com [NC]
RewriteRule .* - [F,L]
#prevent image hotlinking
######################################################
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.ca/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ - [F]
#use a default image for broken links
######################################################
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^images/.*\.jpg$ /images/default.jpg [L]
# serve custom error pages
######################################################
# ErrorDocument 400 /errors/400.html
# ErrorDocument 401 /errors/401.html
# ErrorDocument 403 /errors/403.html
# ErrorDocument 404 /errors/404.html
# ErrorDocument 500 /errors/500.html
# automatically corect simple spelling erors
######################################################
#
#CheckSpelling On
#
#block bad bots and site rippers
######################################################
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]
# send em to a hellish website of your choice
######################################################
#RewriteRule ^.*$ http://www.hellish-website.com [R,L]
# block ip addresses
######################################################
#
#order allow,deny
#deny from xxx.xxx.xxx.xxx
#deny from yyy.yyy.yyy.yyy
#allow from all
#
# Gzip our scripts
######################################################
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \
\.(?:exe|t?gz|zip|bz2|sit|rar)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
# Just in case some noob is using an old browser...
######################################################
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# expire headers
######################################################
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/css "access plus 1 hour"
ExpiresByType image/ico A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/x-javascript "access plus 216000 seconds"
# turn off Etags
######################################################
FileETag none
# canonical favicons from css tricks blog post
######################################################
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/favicon.ico$ [NC]
RewriteCond %{REQUEST_URI} /favicon(s)?\.?(gif|ico|jpe?g?|png)?$ [NC]
RewriteRule (.*) http://example.com/favicon.ico [R=301,L]
# canonical robots.txt from css tricks blog post
######################################################
RewriteBase /
RewriteCond %{REQUEST_URI} !^/robots.txt$ [NC]
RewriteCond %{REQUEST_URI} robots\.txt [NC]
RewriteRule .* http://example.com/robots.txt [R=301,L]
# canonical sitemaps from css tricks blog post
######################################################
RedirectMatch 301 /sitemap\.xml$ http://example.com/sitemap.xml
RedirectMatch 301 /sitemap\.xml\.gz$ http://example.com/sitemap.xml.gz
# serve custom error pages
######################################################
#ErrorDocument 400 /errors/400.html
#ErrorDocument 401 /errors/401.html
#ErrorDocument 403 /errors/403.html
#ErrorDocument 404 /errors/404.html
#ErrorDocument 500 /errors/500.html
# add MIME types
# htc for CSS PIE
######################################################
AddType text/x-component htc
# default charset
######################################################
AddDefaultCharset UTF-8
# set the default language
######################################################
DefaultLanguage en-US
# secure htaccess file
######################################################
#
#order allow,deny
# deny from all
#
# secure wordpress contact forms via referrer check
######################################################
#RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
#RewriteCond %{REQUEST_POST} .*contact.php$
#RewriteRule .* - [F]
# protect wp-config in wordpress
######################################################
#
#order allow,deny
#deny from all
#
# limit file uploads to 10mb
######################################################
#LimitRequestBody 10240000