router.php 959 B

1234567891011121314151617181920212223242526
  1. <?php
  2. /**
  3. * Router for the PHP built-in server used in local development:
  4. *
  5. * php -S localhost:8080 router.php
  6. *
  7. * The built-in server does not read .htaccess, so this mirrors the production
  8. * protection rules — otherwise data/*.json (which contains gallery password
  9. * hashes) and other internals would be readable while testing locally.
  10. * Not used in production; Apache ignores it.
  11. */
  12. $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?? '/';
  13. $blocked = preg_match('#^/(app|config|data|docs)/#', $path) // internals
  14. || preg_match('#(^|/)\.[^/]#', $path) // dotfiles/dirs
  15. || preg_match('#\.(json|md|lock)$#', $path) // data/docs
  16. || str_ends_with($path, '.sample.php'); // config templates
  17. if ($blocked) {
  18. http_response_code(403);
  19. echo 'Forbidden';
  20. return true;
  21. }
  22. // Let the built-in server serve the requested file (or its own 404) as usual.
  23. return false;