.htaccess 7.4 KB

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