Chris@0: #
Chris@0: # Apache/PHP/Drupal settings:
Chris@0: #
Chris@0:
Chris@0: # Protect files and directories from prying eyes.
Chris@0:
Chris@0:
Chris@0: Require all denied
Chris@0:
Chris@0:
Chris@0: Order allow,deny
Chris@0:
Chris@0:
Chris@0:
Chris@0: # Don't show directory listings for URLs which map to a directory.
Chris@0: Options -Indexes
Chris@0:
Chris@0: # Set the default handler.
Chris@0: DirectoryIndex index.php index.html index.htm
Chris@0:
Chris@0: # Add correct encoding for SVGZ.
Chris@0: AddType image/svg+xml svg svgz
Chris@0: AddEncoding gzip svgz
Chris@0:
Chris@0: # Most of the following PHP settings cannot be changed at runtime. See
Chris@0: # sites/default/default.settings.php and
Chris@0: # Drupal\Core\DrupalKernel::bootEnvironment() for settings that can be
Chris@0: # changed at runtime.
Chris@0:
Chris@0: # PHP 5, Apache 1 and 2.
Chris@0:
Chris@0: php_value assert.active 0
Chris@0: php_flag session.auto_start off
Chris@0: php_value mbstring.http_input pass
Chris@0: php_value mbstring.http_output pass
Chris@0: php_flag mbstring.encoding_translation off
Chris@0: # PHP 5.6 has deprecated $HTTP_RAW_POST_DATA and produces warnings if this is
Chris@0: # not set.
Chris@0: php_value always_populate_raw_post_data -1
Chris@0:
Chris@0:
Chris@0: # Requires mod_expires to be enabled.
Chris@0:
Chris@0: # Enable expirations.
Chris@0: ExpiresActive On
Chris@0:
Chris@0: # Cache all files for 2 weeks after access (A).
Chris@0: ExpiresDefault A1209600
Chris@0:
Chris@0:
Chris@0: # Do not allow PHP scripts to be cached unless they explicitly send cache
Chris@0: # headers themselves. Otherwise all scripts would have to overwrite the
Chris@0: # headers set by mod_expires if they want another caching behavior. This may
Chris@0: # fail if an error occurs early in the bootstrap process, and it may cause
Chris@0: # problems if a non-Drupal PHP file is installed in a subdirectory.
Chris@0: ExpiresActive Off
Chris@0:
Chris@0:
Chris@0:
Chris@0: # Set a fallback resource if mod_rewrite is not enabled. This allows Drupal to
Chris@0: # work without clean URLs. This requires Apache version >= 2.2.16. If Drupal is
Chris@0: # not accessed by the top level URL (i.e.: http://example.com/drupal/ instead of
Chris@0: # http://example.com/), the path to index.php will need to be adjusted.
Chris@0:
Chris@0: FallbackResource /index.php
Chris@0:
Chris@0:
Chris@0: # Various rewrite rules.
Chris@0:
Chris@0: RewriteEngine on
Chris@0:
Chris@0: # Set "protossl" to "s" if we were accessed via https://. This is used later
Chris@0: # if you enable "www." stripping or enforcement, in order to ensure that
Chris@0: # you don't bounce between http and https.
Chris@0: RewriteRule ^ - [E=protossl]
Chris@0: RewriteCond %{HTTPS} on
Chris@0: RewriteRule ^ - [E=protossl:s]
Chris@0:
Chris@0: # Make sure Authorization HTTP header is available to PHP
Chris@0: # even when running as CGI or FastCGI.
Chris@0: RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Chris@0:
Chris@0: # Block access to "hidden" directories whose names begin with a period. This
Chris@0: # includes directories used by version control systems such as Subversion or
Chris@0: # Git to store control files. Files whose names begin with a period, as well
Chris@0: # as the control files used by CVS, are protected by the FilesMatch directive
Chris@0: # above.
Chris@0: #
Chris@0: # NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
Chris@0: # not possible to block access to entire directories from .htaccess because
Chris@0: # is not allowed here.
Chris@0: #
Chris@0: # If you do not have mod_rewrite installed, you should remove these
Chris@0: # directories from your webroot or otherwise protect them from being
Chris@0: # downloaded.
Chris@0: RewriteRule "/\.|^\.(?!well-known/)" - [F]
Chris@0:
Chris@0: # If your site can be accessed both with and without the 'www.' prefix, you
Chris@0: # can use one of the following settings to redirect users to your preferred
Chris@0: # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
Chris@0: #
Chris@0: # To redirect all users to access the site WITH the 'www.' prefix,
Chris@0: # (http://example.com/foo will be redirected to http://www.example.com/foo)
Chris@0: # uncomment the following:
Chris@0: # RewriteCond %{HTTP_HOST} .
Chris@0: # RewriteCond %{HTTP_HOST} !^www\. [NC]
Chris@0: # RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Chris@0: #
Chris@0: # To redirect all users to access the site WITHOUT the 'www.' prefix,
Chris@0: # (http://www.example.com/foo will be redirected to http://example.com/foo)
Chris@0: # uncomment the following:
Chris@0: # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
Chris@0: # RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
Chris@0:
Chris@0: # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
Chris@0: # VirtualDocumentRoot and the rewrite rules are not working properly.
Chris@0: # For example if your site is at http://example.com/drupal uncomment and
Chris@0: # modify the following line:
Chris@0: # RewriteBase /drupal
Chris@0: #
Chris@0: # If your site is running in a VirtualDocumentRoot at http://example.com/,
Chris@0: # uncomment the following line:
Chris@0: # RewriteBase /
Chris@0:
Chris@0: # Redirect common PHP files to their new locations.
Chris@0: RewriteCond %{REQUEST_URI} ^(.*)?/(install.php) [OR]
Chris@0: RewriteCond %{REQUEST_URI} ^(.*)?/(rebuild.php)
Chris@0: RewriteCond %{REQUEST_URI} !core
Chris@0: RewriteRule ^ %1/core/%2 [L,QSA,R=301]
Chris@0:
Chris@0: # Rewrite install.php during installation to see if mod_rewrite is working
Chris@0: RewriteRule ^core/install.php core/install.php?rewrite=ok [QSA,L]
Chris@0:
Chris@0: # Pass all requests not referring directly to files in the filesystem to
Chris@0: # index.php.
Chris@0: RewriteCond %{REQUEST_FILENAME} !-f
Chris@0: RewriteCond %{REQUEST_FILENAME} !-d
Chris@0: RewriteCond %{REQUEST_URI} !=/favicon.ico
Chris@0: RewriteRule ^ index.php [L]
Chris@0:
Chris@0: # For security reasons, deny access to other PHP files on public sites.
Chris@0: # Note: The following URI conditions are not anchored at the start (^),
Chris@0: # because Drupal may be located in a subdirectory. To further improve
Chris@0: # security, you can replace '!/' with '!^/'.
Chris@0: # Allow access to PHP files in /core (like authorize.php or install.php):
Chris@0: RewriteCond %{REQUEST_URI} !/core/[^/]*\.php$
Chris@0: # Allow access to test-specific PHP files:
Chris@0: RewriteCond %{REQUEST_URI} !/core/modules/system/tests/https?.php
Chris@0: # Allow access to Statistics module's custom front controller.
Chris@0: # Copy and adapt this rule to directly execute PHP files in contributed or
Chris@0: # custom modules or to run another PHP application in the same directory.
Chris@0: RewriteCond %{REQUEST_URI} !/core/modules/statistics/statistics.php$
Chris@0: # Deny access to any other PHP files that do not match the rules above.
Chris@0: # Specifically, disallow autoload.php from being served directly.
Chris@0: RewriteRule "^(.+/.*|autoload)\.php($|/)" - [F]
Chris@0:
Chris@0: # Rules to correctly serve gzip compressed CSS and JS files.
Chris@0: # Requires both mod_rewrite and mod_headers to be enabled.
Chris@0:
Chris@0: # Serve gzip compressed CSS files if they exist and the client accepts gzip.
Chris@0: RewriteCond %{HTTP:Accept-encoding} gzip
Chris@0: RewriteCond %{REQUEST_FILENAME}\.gz -s
Chris@0: RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
Chris@0:
Chris@0: # Serve gzip compressed JS files if they exist and the client accepts gzip.
Chris@0: RewriteCond %{HTTP:Accept-encoding} gzip
Chris@0: RewriteCond %{REQUEST_FILENAME}\.gz -s
Chris@0: RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
Chris@0:
Chris@0: # Serve correct content types, and prevent mod_deflate double gzip.
Chris@0: RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
Chris@0: RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
Chris@0:
Chris@0:
Chris@0: # Serve correct encoding type.
Chris@0: Header set Content-Encoding gzip
Chris@0: # Force proxies to cache gzipped & non-gzipped css/js files separately.
Chris@0: Header append Vary Accept-Encoding
Chris@0:
Chris@0:
Chris@0:
Chris@0:
Chris@0: # Various header fixes.
Chris@0:
Chris@0: # Disable content sniffing, since it's an attack vector.
Chris@0: Header always set X-Content-Type-Options nosniff
Chris@0: # Disable Proxy header, since it's an attack vector.
Chris@0: RequestHeader unset Proxy
Chris@0: