.htaccess 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. ## Begin RewriteBase
  4. # If you are getting 500 or 404 errors on subpages, you may have to uncomment the RewriteBase entry
  5. # You should change the '/' to your appropriate subfolder. For example if you have
  6. # your Grav install at the root of your site '/' should work, else it might be something
  7. # along the lines of: RewriteBase /<your_sub_folder>
  8. ##
  9. # RewriteBase /
  10. ## End - RewriteBase
  11. ## Begin - X-Forwarded-Proto
  12. # In some hosted or load balanced environments, SSL negotiation happens upstream.
  13. # In order for Grav to recognize the connection as secure, you need to uncomment
  14. # the following lines.
  15. #
  16. # RewriteCond %{HTTP:X-Forwarded-Proto} https
  17. # RewriteRule .* - [E=HTTPS:on]
  18. #
  19. ## End - X-Forwarded-Proto
  20. ## Begin - Exploits
  21. # If you experience problems on your site block out the operations listed below
  22. # This attempts to block the most common type of exploit `attempts` to Grav
  23. #
  24. # Block out any script trying to use twig tags in URL.
  25. RewriteCond %{REQUEST_URI} ({{|}}|{%|%}) [OR]
  26. RewriteCond %{QUERY_STRING} ({{|}}|{%25|%25}) [OR]
  27. # Block out any script trying to base64_encode data within the URL.
  28. RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
  29. # Block out any script that includes a <script> tag in URL.
  30. RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
  31. # Block out any script trying to set a PHP GLOBALS variable via URL.
  32. RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
  33. # Block out any script trying to modify a _REQUEST variable via URL.
  34. RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
  35. # Return 403 Forbidden header and show the content of the root homepage
  36. RewriteRule .* index.php [F]
  37. #
  38. ## End - Exploits
  39. ## Begin - Index
  40. # If the requested path and file is not /index.php and the request
  41. # has not already been internally rewritten to the index.php script
  42. RewriteCond %{REQUEST_URI} !^/index\.php
  43. # and the requested path and file doesn't directly match a physical file
  44. RewriteCond %{REQUEST_FILENAME} !-f
  45. # and the requested path and file doesn't directly match a physical folder
  46. RewriteCond %{REQUEST_FILENAME} !-d
  47. # internally rewrite the request to the index.php script
  48. RewriteRule .* index.php [L]
  49. ## End - Index
  50. ## Begin - Security
  51. # Block all direct access for these folders
  52. RewriteRule ^(\.git|cache|bin|logs|backup|webserver-configs|tests)/(.*) error [F]
  53. # Block access to specific file types for these system folders
  54. RewriteRule ^(system|vendor)/(.*)\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ error [F]
  55. # Block access to specific file types for these user folders
  56. RewriteRule ^(user)/(.*)\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ error [F]
  57. # Block all direct access to .md files:
  58. RewriteRule \.md$ error [F]
  59. # Block all direct access to files and folders beginning with a dot
  60. RewriteRule (^|/)\.(?!well-known) - [F]
  61. # Block access to specific files in the root folder
  62. RewriteRule ^(LICENSE\.txt|composer\.lock|composer\.json|\.htaccess)$ error [F]
  63. ## End - Security
  64. </IfModule>
  65. # Begin - Prevent Browsing and Set Default Resources
  66. Options -Indexes
  67. DirectoryIndex index.php index.html index.htm
  68. # End - Prevent Browsing and Set Default Resources