diff --git a/public/.htaccess b/public/.htaccess index 5b0f43f..295e754 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -2,49 +2,35 @@ RewriteEngine On RewriteBase / - # Don't rewrite files or directories that exist + # Allow Next.js static files and assets + RewriteRule ^_next/ - [L] + RewriteRule ^static/ - [L] + + # Serve existing files or directories directly + RewriteCond %{REQUEST_FILENAME} -f [OR] + RewriteCond %{REQUEST_FILENAME} -d + RewriteRule ^ - [L] + + # Redirect extensionless URLs to trailing slash directories + # Works with "trailingSlash: true" and static export RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_URI} !/$ + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}/index.html -f + RewriteRule ^(.+)$ /$1/ [R=301,L] - # For URLs with trailing slash, try to serve index.html from that directory - RewriteCond %{REQUEST_URI} ^(.+)/$ - RewriteCond %{DOCUMENT_ROOT}%1/index.html -f - RewriteRule ^(.+)/$ /$1/index.html [L,QSA] - - # For URLs without trailing slash, redirect to trailing slash version - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_URI} !(.*)/$ - RewriteRule ^(.*)$ $1/ [L,R=301] - - # Fallback to 404 page - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule . /404.html [L] + # Apache 404 (Next.js static export supports 404.html) + ErrorDocument 404 /404.html -# Set proper MIME types - - AddType text/html .html - AddType application/javascript .js - AddType text/css .css - AddType image/webp .webp - AddType image/svg+xml .svg - + + # Cache static assets aggressively + + Header set Cache-Control "public, max-age=31536000, immutable" + -# Enable compression - - AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json image/svg+xml - - -# Browser caching - - ExpiresActive On - ExpiresByType text/html "access plus 0 seconds" - ExpiresByType text/css "access plus 1 year" - ExpiresByType application/javascript "access plus 1 year" - ExpiresByType image/webp "access plus 1 year" - ExpiresByType image/svg+xml "access plus 1 year" - ExpiresByType image/png "access plus 1 year" - ExpiresByType image/jpeg "access plus 1 year" + # HTML is not cached (important for updated content) + + Header set Cache-Control "public, max-age=0, must-revalidate" +