.htaccess 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. ## Begin RewriteBase
  4. # If you are getting 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 - Exploits
  12. # If you experience problems on your site block out the operations listed below
  13. # This attempts to block the most common type of exploit `attempts` to Grav
  14. #
  15. # Block out any script trying to base64_encode data within the URL.
  16. RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
  17. # Block out any script that includes a <script> tag in URL.
  18. RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
  19. # Block out any script trying to set a PHP GLOBALS variable via URL.
  20. RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
  21. # Block out any script trying to modify a _REQUEST variable via URL.
  22. RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
  23. # Return 403 Forbidden header and show the content of the root homepage
  24. RewriteRule .* index.php [F]
  25. #
  26. ## End - Exploits
  27. ## Begin - Index
  28. # If the requested path and file is not /index.php and the request
  29. # has not already been internally rewritten to the index.php script
  30. RewriteCond %{REQUEST_URI} !^/index\.php
  31. # and the requested path and file doesn't directly match a physical file
  32. RewriteCond %{REQUEST_FILENAME} !-f
  33. # and the requested path and file doesn't directly match a physical folder
  34. RewriteCond %{REQUEST_FILENAME} !-d
  35. # internally rewrite the request to the index.php script
  36. RewriteRule .* index.php [L]
  37. ## End - Index
  38. ## Begin - Security
  39. # Block all direct access for these folders
  40. RewriteRule ^(.git|cache|bin|logs|backup)/(.*) error [L]
  41. # Block access to specific file types for these folders
  42. RewriteRule ^(system|user|vendor)/(.*)\.(txt|md|html|yaml|php|twig|sh|bat)$ error [L]
  43. # Block all direct access to .md files:
  44. RewriteRule \.md$ error [L]
  45. # Block all direct access to files and folders beginning with a dot
  46. RewriteRule (^\.|/\.) - [F]
  47. # Block access to specific files in the root folder
  48. RewriteRule ^(LICENSE|composer.lock|composer.json|nginx.conf|web.config)$ error [F]
  49. ## End - Security
  50. </IfModule>
  51. # Begin - Prevent Browsing and Set Default Resources
  52. Options -Indexes
  53. DirectoryIndex index.php index.html index.htm
  54. # End - Prevent Browsing and Set Default Resources