.htaccess 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #
  2. # Apache/PHP/Drupal settings:
  3. #
  4. # Protect files and directories from prying eyes.
  5. <FilesMatch "\.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$">
  6. <IfModule mod_authz_core.c>
  7. Require all denied
  8. </IfModule>
  9. <IfModule !mod_authz_core.c>
  10. Order allow,deny
  11. </IfModule>
  12. </FilesMatch>
  13. # Don't show directory listings for URLs which map to a directory.
  14. Options -Indexes
  15. # Set the default handler.
  16. DirectoryIndex index.php index.html index.htm
  17. # Add correct encoding for SVGZ.
  18. AddType image/svg+xml svg svgz
  19. AddEncoding gzip svgz
  20. # Most of the following PHP settings cannot be changed at runtime. See
  21. # sites/default/default.settings.php and
  22. # Drupal\Core\DrupalKernel::bootEnvironment() for settings that can be
  23. # changed at runtime.
  24. # PHP 5, Apache 1 and 2.
  25. <IfModule mod_php5.c>
  26. php_value assert.active 0
  27. php_flag session.auto_start off
  28. php_value mbstring.http_input pass
  29. php_value mbstring.http_output pass
  30. php_flag mbstring.encoding_translation off
  31. # PHP 5.6 has deprecated $HTTP_RAW_POST_DATA and produces warnings if this is
  32. # not set.
  33. php_value always_populate_raw_post_data -1
  34. </IfModule>
  35. # Requires mod_expires to be enabled.
  36. <IfModule mod_expires.c>
  37. # Enable expirations.
  38. ExpiresActive On
  39. # Cache all files for 2 weeks after access (A).
  40. ExpiresDefault A1209600
  41. <FilesMatch \.php$>
  42. # Do not allow PHP scripts to be cached unless they explicitly send cache
  43. # headers themselves. Otherwise all scripts would have to overwrite the
  44. # headers set by mod_expires if they want another caching behavior. This may
  45. # fail if an error occurs early in the bootstrap process, and it may cause
  46. # problems if a non-Drupal PHP file is installed in a subdirectory.
  47. ExpiresActive Off
  48. </FilesMatch>
  49. </IfModule>
  50. # Set a fallback resource if mod_rewrite is not enabled. This allows Drupal to
  51. # work without clean URLs. This requires Apache version >= 2.2.16. If Drupal is
  52. # not accessed by the top level URL (i.e.: http://example.com/drupal/ instead of
  53. # http://example.com/), the path to index.php will need to be adjusted.
  54. <IfModule !mod_rewrite.c>
  55. FallbackResource /index.php
  56. </IfModule>
  57. # Various rewrite rules.
  58. <IfModule mod_rewrite.c>
  59. RewriteEngine on
  60. # Set "protossl" to "s" if we were accessed via https://. This is used later
  61. # if you enable "www." stripping or enforcement, in order to ensure that
  62. # you don't bounce between http and https.
  63. RewriteRule ^ - [E=protossl]
  64. RewriteCond %{HTTPS} on
  65. RewriteRule ^ - [E=protossl:s]
  66. # Make sure Authorization HTTP header is available to PHP
  67. # even when running as CGI or FastCGI.
  68. RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  69. # Block access to "hidden" directories whose names begin with a period. This
  70. # includes directories used by version control systems such as Subversion or
  71. # Git to store control files. Files whose names begin with a period, as well
  72. # as the control files used by CVS, are protected by the FilesMatch directive
  73. # above.
  74. #
  75. # NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
  76. # not possible to block access to entire directories from .htaccess because
  77. # <DirectoryMatch> is not allowed here.
  78. #
  79. # If you do not have mod_rewrite installed, you should remove these
  80. # directories from your webroot or otherwise protect them from being
  81. # downloaded.
  82. RewriteRule "(^|/)\.(?!well-known)" - [F]
  83. # If your site can be accessed both with and without the 'www.' prefix, you
  84. # can use one of the following settings to redirect users to your preferred
  85. # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  86. #
  87. # To redirect all users to access the site WITH the 'www.' prefix,
  88. # (http://example.com/foo will be redirected to http://www.example.com/foo)
  89. # uncomment the following:
  90. # RewriteCond %{HTTP_HOST} .
  91. # RewriteCond %{HTTP_HOST} !^www\. [NC]
  92. # RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  93. #
  94. # To redirect all users to access the site WITHOUT the 'www.' prefix,
  95. # (http://www.example.com/foo will be redirected to http://example.com/foo)
  96. # uncomment the following:
  97. # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  98. # RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
  99. # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  100. # VirtualDocumentRoot and the rewrite rules are not working properly.
  101. # For example if your site is at http://example.com/drupal uncomment and
  102. # modify the following line:
  103. # RewriteBase /drupal
  104. #
  105. # If your site is running in a VirtualDocumentRoot at http://example.com/,
  106. # uncomment the following line:
  107. # RewriteBase /
  108. # Redirect common PHP files to their new locations.
  109. RewriteCond %{REQUEST_URI} ^(.*)?/(install.php) [OR]
  110. RewriteCond %{REQUEST_URI} ^(.*)?/(rebuild.php)
  111. RewriteCond %{REQUEST_URI} !core
  112. RewriteRule ^ %1/core/%2 [L,QSA,R=301]
  113. # Rewrite install.php during installation to see if mod_rewrite is working
  114. RewriteRule ^core/install.php core/install.php?rewrite=ok [QSA,L]
  115. # Pass all requests not referring directly to files in the filesystem to
  116. # index.php.
  117. RewriteCond %{REQUEST_FILENAME} !-f
  118. RewriteCond %{REQUEST_FILENAME} !-d
  119. RewriteCond %{REQUEST_URI} !=/favicon.ico
  120. RewriteRule ^ index.php [L]
  121. # For security reasons, deny access to other PHP files on public sites.
  122. # Note: The following URI conditions are not anchored at the start (^),
  123. # because Drupal may be located in a subdirectory. To further improve
  124. # security, you can replace '!/' with '!^/'.
  125. # Allow access to PHP files in /core (like authorize.php or install.php):
  126. RewriteCond %{REQUEST_URI} !/core/[^/]*\.php$
  127. # Allow access to test-specific PHP files:
  128. RewriteCond %{REQUEST_URI} !/core/modules/system/tests/https?.php
  129. # Allow access to Statistics module's custom front controller.
  130. # Copy and adapt this rule to directly execute PHP files in contributed or
  131. # custom modules or to run another PHP application in the same directory.
  132. RewriteCond %{REQUEST_URI} !/core/modules/statistics/statistics.php$
  133. # Deny access to any other PHP files that do not match the rules above.
  134. # Specifically, disallow autoload.php from being served directly.
  135. RewriteRule "^(.+/.*|autoload)\.php($|/)" - [F]
  136. # Rules to correctly serve gzip compressed CSS and JS files.
  137. # Requires both mod_rewrite and mod_headers to be enabled.
  138. <IfModule mod_headers.c>
  139. # Serve gzip compressed CSS files if they exist and the client accepts gzip.
  140. RewriteCond %{HTTP:Accept-encoding} gzip
  141. RewriteCond %{REQUEST_FILENAME}\.gz -s
  142. RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
  143. # Serve gzip compressed JS files if they exist and the client accepts gzip.
  144. RewriteCond %{HTTP:Accept-encoding} gzip
  145. RewriteCond %{REQUEST_FILENAME}\.gz -s
  146. RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
  147. # Serve correct content types, and prevent mod_deflate double gzip.
  148. RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
  149. RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
  150. <FilesMatch "(\.js\.gz|\.css\.gz)$">
  151. # Serve correct encoding type.
  152. Header set Content-Encoding gzip
  153. # Force proxies to cache gzipped & non-gzipped css/js files separately.
  154. Header append Vary Accept-Encoding
  155. </FilesMatch>
  156. </IfModule>
  157. </IfModule>
  158. # Various header fixes.
  159. <IfModule mod_headers.c>
  160. # Disable content sniffing, since it's an attack vector.
  161. Header always set X-Content-Type-Options nosniff
  162. # Disable Proxy header, since it's an attack vector.
  163. RequestHeader unset Proxy
  164. </IfModule>