.htaccess 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # 面试管理系统 Apache 配置
  2. # 启用 Rewrite 引擎
  3. <IfModule mod_rewrite.c>
  4. RewriteEngine On
  5. RewriteBase /
  6. # 如果请求文件不存在,重定向到 index.html
  7. RewriteRule ^index\.html$ - [L]
  8. RewriteCond %{REQUEST_FILENAME} !-f
  9. RewriteCond %{REQUEST_FILENAME} !-d
  10. RewriteRule . /index.html [L]
  11. </IfModule>
  12. # MIME 类型设置
  13. <IfModule mod_mime.c>
  14. # JavaScript
  15. AddType application/javascript js
  16. AddType application/json json
  17. # Fonts
  18. AddType font/woff woff
  19. AddType font/woff2 woff2
  20. AddType font/ttf ttf
  21. AddType application/vnd.ms-fontobject eot
  22. # Images
  23. AddType image/svg+xml svg svgz
  24. </IfModule>
  25. # 启用 Gzip 压缩
  26. <IfModule mod_deflate.c>
  27. # HTML, CSS, JavaScript, Text, XML
  28. AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml
  29. </IfModule>
  30. # 设置缓存
  31. <IfModule mod_expires.c>
  32. ExpiresActive On
  33. # 图片缓存 1 年
  34. ExpiresByType image/jpeg "access plus 1 year"
  35. ExpiresByType image/png "access plus 1 year"
  36. ExpiresByType image/gif "access plus 1 year"
  37. ExpiresByType image/svg+xml "access plus 1 year"
  38. # CSS 和 JavaScript 缓存 1 年
  39. ExpiresByType text/css "access plus 1 year"
  40. ExpiresByType application/javascript "access plus 1 year"
  41. ExpiresByType application/json "access plus 1 year"
  42. # 字体文件缓存 1 年
  43. ExpiresByType font/woff "access plus 1 year"
  44. ExpiresByType font/woff2 "access plus 1 year"
  45. ExpiresByType font/ttf "access plus 1 year"
  46. ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
  47. # HTML 不缓存
  48. ExpiresByType text/html "access plus 0 seconds"
  49. </IfModule>
  50. # 安全头设置
  51. <IfModule mod_headers.c>
  52. # X-Frame-Options
  53. Header always set X-Frame-Options "SAMEORIGIN"
  54. # X-Content-Type-Options
  55. Header always set X-Content-Type-Options "nosniff"
  56. # X-XSS-Protection
  57. Header always set X-XSS-Protection "1; mode=block"
  58. # Content-Security-Policy(根据实际情况调整)
  59. Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:"
  60. </IfModule>
  61. # 禁止访问隐藏文件
  62. <FilesMatch "^\.">
  63. Order allow,deny
  64. Deny from all
  65. </FilesMatch>
  66. # 禁止访问特定文件
  67. <FilesMatch "(\.git|\.svn)">
  68. Order allow,deny
  69. Deny from all
  70. </FilesMatch>
  71. # 错误页面(可选)
  72. ErrorDocument 404 /index.html