Files
Website/.htaccess
2026-04-17 00:26:03 +01:00

133 lines
4.3 KiB
ApacheConf

# ArcaneNeko Website - .htaccess Configuration
# Apache server configuration rules
# Enable Rewrite Engine
RewriteEngine On
RewriteBase /
# ============================================
# Remove .html extension from URLs
# ============================================
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ $1.html [L]
# ============================================
# SECURITY & BASIC PROTECTION
# ============================================
# Block access to hidden files (dotfiles)
<Files ~ "^\.">
Require all denied
</Files>
# Block access to config and environment files
<FilesMatch "\.(env|config|conf|log|sh|sql)$">
Require all denied
</FilesMatch>
# ============================================
# CUSTOM ERROR PAGES
# ============================================
ErrorDocument 400 /400
ErrorDocument 403 /403
ErrorDocument 404 /404
ErrorDocument 500 /500
ErrorDocument 502 /502
ErrorDocument 503 /503
# ============================================
# CACHE CONTROL & PERFORMANCE
# ============================================
# Static assets caching - 1 year
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|webp|svg|eot|otf|woff|woff2|ttf|css|js)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# HTML documents - no cache
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "0"
</FilesMatch>
# ============================================
# BROWSER CACHING & COMPRESSION
# ============================================
# Enable Gzip compression (mod_deflate)
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/x-javascript application/json application/rss+xml font/ttf font/otf
</IfModule>
# ============================================
# MIME TYPES & FONT ACCESS
# ============================================
# Allow CORS for web fonts
<FilesMatch "\.(woff|woff2|ttf|eot|svg)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
# ============================================
# SECURITY HEADERS
# ============================================
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "DENY"
Header set X-XSS-Protection "1; mode=block"
Header set Referrer-Policy "strict-origin-when-cross-origin"
Header set Permissions-Policy "geolocation=(), microphone=(), camera=()"
# ============================================
# SITEMAP
# ============================================
RewriteRule ^sitemap\.xml$ /sitemap.xml [L]
# ============================================
# ROBOTS.TXT
# ============================================
RewriteRule ^robots\.txt$ /robots.txt [L]
# ============================================
# HTTPS & FORCE SSL (optional)
# ============================================
# Uncomment the next 3 lines to force HTTPS redirect
# RewriteCond %{HTTPS} off
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ============================================
# PHP & SERVER-SIDE PROCESSING (optional)
# ============================================
# If your site needs PHP, uncomment:
# AddType application/x-httpd-php .php
# DirectoryIndex index.php index.html
# ============================================
# CLIENT SIDE ROUTING (SPA support - optional)
# ============================================
# For single-page applications, route all non-file/non-api requests to index.html
# Uncomment if you implement client-side routing
#
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^ index.html [L]
# ============================================
# NGINX COMPATIBILITY NOTES
# ============================================
# This .htaccess is for Apache. If running with Nginx:
# - Nginx does not support .htaccess; rules must be in server config
# - ErrorDocument directives need server-level config in Nginx
# - Header directives need 'add_header' in Nginx context
# - Rewrite rules need 'rewrite' directive in Nginx
#
# Example Nginx config for static assets:
# location ~* \.(ico|pdf|flv|jpg|jpeg|png|gif|webp|svg|eot|otf|woff|woff2|ttf|css|js)$ {
# expires 1y;
# add_header Cache-Control "public";
# try_files $uri =404;
# }
#
# Example Nginx config for sitemap:
# rewrite ^/sitemap.xml$ /sitemap.xml break;