The perfect .htaccess file

Created by: laetzer, Last modification: 25 Feb 2010 (04:27 UTC)
Bitweaver does not write an .htaccess file to its root directory after install. If you need one there, you must create it. Bitweaver does, however, write .htaccess-files to certain subdirectories, which are needed for features like prettyURLs. Note that .htaccess files are only relevant on Apache web servers. Some of these options are commented by default because if your server does not allow them to be set, they take your site offline as long as they are in place. To use them, uncomment them one by one. See also: The perfect robots.txt for Bitweaver.

/.htaccess


#########
# if your server has the module mod_rewrite
# you can use this, to route certain links to certain pages
# below are 2 examples
# this works similiar to Bitweaver's prettyURLs ...
# the downside:
# you can't anymore have directories (packages) called "contact/" or "privacy/":
#
<IfModule mod_rewrite.c>
    RewriteEngine On
    Redirect 302 /about /wiki/About
    Redirect 302 /privacy /wiki/Privacy
</IfModule>



#########
# if your server allows it
# certain php.ini settings can be controlled
# for instance, magic quotes can be turned off
# as recommended by Bitweaver's installer:
#
# php_flag magic_quotes_gpc off



#########
# if your server allows it
# -Indexes excludes directories to be browsed directly
# and FollowSymLinks is needed for prettyURLs
#
# Options -Indexes FollowSymLinks



#########
# if your server has the module mod_deflate
# with this, you can GZIP compress all text-based content
# and gain great performance
# if this is used, Bitweaver's GZIP-compression in Admin > Kernel should be disabled
# otherwise the content might be compressed more than once which might lead to errors
# this compression does not show up in Bitweaver's "Server Info" module
#
<IfModule mod_deflate.c>
  <FilesMatch "\.(js|css|php|eot|ttf|otf|svg)$">
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>



#########
# if your server has the module mod_headers
# use this to control ETags
# which is said to be better for performance
#
<IfModule mod_headers.c>
    Header unset ETag
</IfModule>
FileETag None



#########
# ONLY if your site is LIVE, use this for performance
# because while you're still developing, caches should be disabled
# the idea should be to cache everything except html/php for a long time
# unless it was modified
# and to cache html/php for only a few minutes
#
<IfModule mod_headers.c>

    # "unset Pragma" needs a lot of testing
    # it does not always work well between the chunks that
    # Registered/Admin versus Anonymous are allowed to see
    #
    # Header unset Pragma

    <FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
        Header set Cache-Control "max-age=31536000, public"
        Header unset Last-Modified
    </FilesMatch>
    <FilesMatch "\\.(css)$">
        Header set Cache-Control "max-age=31536000, public"
    </FilesMatch>
    <FilesMatch "\\.(js)$">
        Header set Cache-Control "max-age=31536000, private"
        Header unset Last-Modified
    </FilesMatch>
    <FilesMatch "\\.(x?html?|php)$">
        Header set Cache-Control "max-age=600, private, must-revalidate"
    </FilesMatch>
</IfModule>



#########
# if your server has mod_expires, you can also use this, instead of the above
# you only need to apply one way to control caching, either with mod_expires OR with mod_headers
# I think
# if you test these, please post your results here
#
#<IfModule mod_expires.c>
#    ExpiresActive On
#    ExpiresDefault "access plus 1 seconds"
#    ExpiresByType image/x-icon "access plus 1 year"
#    ExpiresByType image/ico "access plus 1 year"
#    ExpiresByType image/jpeg "access plus 1 year"
#    ExpiresByType image/png "access plus 1 year"
#    ExpiresByType image/gif "access plus 1 year"
#    ExpiresByType application/x-shockwave-flash "access plus 1 year"
#    ExpiresByType text/css "access plus 1 year"
#    ExpiresByType text/javascript "access plus 1 year"
#    ExpiresByType application/x-javascript "access plus 1 year"
#    ExpiresByType text/html "access plus 600 seconds"
#    ExpiresByType application/xhtml+xml "access plus 600 seconds"
#</IfModule>



#########
# turning PHP's error handling OFF for LIVE sites
# because it's only needed during development
# other settings to be considered are in kernel/config_inc.php
#
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors on
php_flag ignore_repeated_source on
php_flag report_memleaks off
php_flag track_errors off
php_value docref_root 0
php_value docref_ext 0
php_value error_reporting 0
php_value log_errors_max_len 0



#########
# OR turning PHP's error handling ON for DEVELOPMENT sites
# because it's only needed during development
# other settings to be considered are in kernel/config_inc.php
# not that errors are written to temp/
#
# php_flag display_startup_errors off
# php_flag display_errors off
# php_flag html_errors off
# php_flag log_errors on
# php_flag ignore_repeated_errors on
# php_flag ignore_repeated_source on
# php_flag report_memleaks on
# php_flag track_errors on
# php_value docref_root 0
# php_value docref_ext 0
# php_value error_reporting 2147483647
# php_value log_errors_max_len 0
# php_value error_log /home/bitweaver/bitweaver/temp/PHP_errors.log



#########
# how to exclude a certain file
# example
#
#<Files /home/path/public_html/domain/PHP_errors.log>
# Order allow,deny
# Deny from all
# Satisfy All
#</Files>



#########
# an application called xdebug *might* be installed on your server
# it slows down a site because it is used for debugging and profiling
# on a production site, it wouldn't normally be enabled
# uncomment this, if your server has xdebug and you need to exclude your site
#
# php_value xdebug.auto_trace 0
# php_value xdebug.trace_format  0
# php_value xdebug.trace_options  0
# php_value xdebug.profiler_enable 0


Most of above settings are written with Apache 2+ in mind. Also, depending on higher level settings in Apache's as well as PHP's config files, some of the above settings might not be allowed (and produce a "Server Error 500").

Test results


...