From bd1fa7fba477073506eb07c59f07a8cc2a69364e Mon Sep 17 00:00:00 2001 From: akash Date: Sat, 6 Dec 2025 21:59:32 +0530 Subject: [PATCH] empty load issue fixed --- package.json | 4 +- public/.htaccess | 79 ++++++++++++++++++++++++++------------- scripts/copy-htaccess.cjs | 18 +++++++++ vercel.json | 29 +++++++++++++- 4 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 scripts/copy-htaccess.cjs diff --git a/package.json b/package.json index 15bc925..b645b54 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build", + "build": "next build && node scripts/copy-htaccess.cjs", "start": "next start", "lint": "eslint", "sitemap": "node scripts/generate-sitemap.cjs" @@ -30,4 +30,4 @@ "eslint-config-next": "16.0.3", "typescript": "^5" } -} +} \ No newline at end of file diff --git a/public/.htaccess b/public/.htaccess index 295e754..f9ae47e 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,36 +1,61 @@ +# Antalya Restaurant - Apache Configuration +# Handles trailing slashes and prevents 403 errors + - RewriteEngine On - RewriteBase / + RewriteEngine On + RewriteBase / - # Allow Next.js static files and assets - RewriteRule ^_next/ - [L] - RewriteRule ^static/ - [L] + # Force HTTPS (optional, uncomment if needed) + # RewriteCond %{HTTPS} off + # RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] - # Serve existing files or directories directly - RewriteCond %{REQUEST_FILENAME} -f [OR] - RewriteCond %{REQUEST_FILENAME} -d - RewriteRule ^ - [L] + # Handle trailing slashes + # If a directory exists with the name, serve its index.html + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_URI} !(.*)/$ + RewriteCond %{REQUEST_FILENAME}/index.html -f + RewriteRule ^(.*)$ $1/ [R=301,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] + # Serve index.html for directories + RewriteCond %{REQUEST_FILENAME} -d + RewriteRule ^(.*)$ $1/index.html [L] - # Apache 404 (Next.js static export supports 404.html) - ErrorDocument 404 /404.html + # Specific rewrites for main pages (with and without trailing slash) + RewriteRule ^about-antalya-restaurant/?$ about-antalya-restaurant/index.html [L] + RewriteRule ^antalya-restaurant-menu/?$ antalya-restaurant-menu/index.html [L] + RewriteRule ^antalya-restaurant-gallery/?$ antalya-restaurant-gallery/index.html [L] + RewriteRule ^book-a-table/?$ book-a-table/index.html [L] + RewriteRule ^catering-services-ontario/?$ catering-services-ontario/index.html [L] + RewriteRule ^antalya-turkish-food-blog/?$ antalya-turkish-food-blog/index.html [L] + + # Blog posts + RewriteRule ^antalya-turkish-food-blog/([^/]+)/?$ antalya-turkish-food-blog/$1/index.html [L] + + # Prevent directory listing + Options -Indexes + + # Custom error pages + ErrorDocument 404 /404.html +# Security Headers - # Cache static assets aggressively - - Header set Cache-Control "public, max-age=31536000, immutable" - - - # HTML is not cached (important for updated content) - - Header set Cache-Control "public, max-age=0, must-revalidate" - + Header set X-Content-Type-Options "nosniff" + Header set X-Frame-Options "DENY" + Header set X-XSS-Protection "1; mode=block" + + +# Cache Control + + ExpiresActive On + ExpiresByType image/jpg "access plus 1 year" + ExpiresByType image/jpeg "access plus 1 year" + ExpiresByType image/gif "access plus 1 year" + ExpiresByType image/png "access plus 1 year" + ExpiresByType image/webp "access plus 1 year" + ExpiresByType image/svg+xml "access plus 1 year" + ExpiresByType text/css "access plus 1 year" + ExpiresByType text/javascript "access plus 1 year" + ExpiresByType application/javascript "access plus 1 year" + ExpiresByType image/x-icon "access plus 1 year" diff --git a/scripts/copy-htaccess.cjs b/scripts/copy-htaccess.cjs new file mode 100644 index 0000000..366a94d --- /dev/null +++ b/scripts/copy-htaccess.cjs @@ -0,0 +1,18 @@ +const fs = require('fs'); +const path = require('path'); + +// Copy .htaccess from public to out directory after build +const source = path.join(__dirname, '..', 'public', '.htaccess'); +const destination = path.join(__dirname, '..', 'out', '.htaccess'); + +try { + if (fs.existsSync(source)) { + fs.copyFileSync(source, destination); + console.log('✓ .htaccess copied to out directory'); + } else { + console.warn('⚠ .htaccess not found in public directory'); + } +} catch (error) { + console.error('Error copying .htaccess:', error.message); + process.exit(1); +} diff --git a/vercel.json b/vercel.json index eead540..446af4c 100644 --- a/vercel.json +++ b/vercel.json @@ -1,34 +1,61 @@ { "trailingSlash": true, - "cleanUrls": false, "rewrites": [ { "source": "/about-antalya-restaurant", "destination": "/about-antalya-restaurant/index.html" }, + { + "source": "/about-antalya-restaurant/", + "destination": "/about-antalya-restaurant/index.html" + }, { "source": "/antalya-restaurant-menu", "destination": "/antalya-restaurant-menu/index.html" }, + { + "source": "/antalya-restaurant-menu/", + "destination": "/antalya-restaurant-menu/index.html" + }, { "source": "/antalya-restaurant-gallery", "destination": "/antalya-restaurant-gallery/index.html" }, + { + "source": "/antalya-restaurant-gallery/", + "destination": "/antalya-restaurant-gallery/index.html" + }, { "source": "/book-a-table", "destination": "/book-a-table/index.html" }, + { + "source": "/book-a-table/", + "destination": "/book-a-table/index.html" + }, { "source": "/catering-services-ontario", "destination": "/catering-services-ontario/index.html" }, + { + "source": "/catering-services-ontario/", + "destination": "/catering-services-ontario/index.html" + }, { "source": "/antalya-turkish-food-blog", "destination": "/antalya-turkish-food-blog/index.html" }, + { + "source": "/antalya-turkish-food-blog/", + "destination": "/antalya-turkish-food-blog/index.html" + }, { "source": "/antalya-turkish-food-blog/:slug", "destination": "/antalya-turkish-food-blog/:slug/index.html" + }, + { + "source": "/antalya-turkish-food-blog/:slug/", + "destination": "/antalya-turkish-food-blog/:slug/index.html" } ], "headers": [