# Chronicle .htaccess file for Apache

# Set Application Environment
#   production  - hide errors, enable caching and aggregation (default)
#   development - show errors, log debug info, no caching or aggregation
#SetEnv APPLICATION_ENV development

# Configure PHP
<IfModule mod_php5.c>
  DirectoryIndex index.php

  # For information on the meaning of these settings, please see:
  # http://www.php.net/manual/en/ini.list.php

  # These settings are required for Perforce Chronicle
  php_value magic_quotes_gpc        false
  php_value magic_quotes_runtime    false
  php_value short_open_tag          true

  # These settings govern how large file uploads can be
  # - The post_max_size value must be larger than upload_max_filesize
  # - The memory_limit value must be larger than post_max_size
  php_value upload_max_filesize     8M
  php_value post_max_size           16M
</IfModule>

# If PHP is not enabled, make default page point to warning
<IfModule !mod_php5.c>
  DirectoryIndex nophp.html
</IfModule>

# Disable MultiViews as it interferes with rewrite
# Disable directory listings for the potential security benefit
Options -MultiViews -Indexes

# Configure Rewrite Engine
<IfModule mod_rewrite.c>
  RewriteEngine On

  <IfModule mod_php5.c>
    # Strip branch component (e.g. '-dev-') from URLs - this is
    # needed for static resources (PHP still sees the original path).
    RewriteRule ^-[^/]+-/?(.*)$          $1

    # Pass through requests for files in safe locations
    RewriteRule ^application/[^/]+/resources/.*$            - [L]
    RewriteRule ^data/sites/[^/]+/resources/.*$             - [L]
    RewriteRule ^data/resources/.*$                         - [L]
    RewriteRule ^sites/[^/]+/modules/[^/]+/resources/.*$    - [L]
    RewriteRule ^sites/[^/]+/themes/.*$                     - [L]
    RewriteRule ^docs/.*$                                   - [L]
    RewriteRule ^favicon\.ico$                              - [L]

    # Externally redirect requests for index.php to '/'
    # (otherwise index.php makes it into the baseUrl)
    RewriteCond %{ENV:REDIRECT_STATUS}  ^$
    RewriteRule ^index\.php(/(.*))?$    /$2         [L,R=permanent]

    # Rewrite all other requests to application
    RewriteRule ^.*$                    index.php   [L]
  </IfModule>

  <IfModule !mod_php5.c>
    # Without PHP, rewrite all requests to warning page
    RewriteRule ^.*$                    nophp.html  [L]
  </IfModule>
</IfModule>

# Configure Static Resource Cache Headers
<IfModule mod_expires.c>
  ExpiresActive   On
  ExpiresDefault  "access plus 12 hours"

  # In order for the cache headers to apply to all static resources under
  # data/resources, data/sites/<name>/resources, sites/<all|name>/themes/,
  # etc. we apply our 12 hour timeout to anything that isn't a php script.
  # The php scripts will quite possibly provide expiration headers on their
  # own but we didn't want them to have to fight this setting.
  <FilesMatch \.php$>
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Enable apache based gzip'ing of text output
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml
</IfModule>

# By default apache ETags include the inode which makes them fail in
# a horizontally scaled environment; we remove inode to fix this and
# to make yslow a happier camper.
FileETag MTime Size

# Disable mod_cache as it serves out the wrong content for dynamic pages.
# Our mod_rewrite rules direct all dynamic requests to index.php, which
# is incompatible with mod_cache's lookups.
<IfModule mod_cache.c>
  SetEnv no-cache
</IfModule>

# Headers for Compressed CSS/JS
AddType     text/css        .cssgz
AddType     text/javascript .jsgz
AddEncoding x-gzip          .cssgz .jsgz