# .htaccess Configuration Template # Version: 2.0 # Date: 2024-12-19 # Description: Optimized template for PLESK Apache + NGINX environments # Instructions: Replace YOURDOMAIN.com with actual domain name #AddType application/x-httpd-php .html # Directory Options Options +FollowSymLinks -MultiViews # Enable Rewrite Engine RewriteEngine On RewriteBase / # ---- HTTPS Enforcement ---- # Force HTTPS first (prevents redirect loops) RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # ---- Same Domain Redirection ---- # Redirect non-www to www (after HTTPS is established) RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} !^localhost [NC] RewriteCond %{HTTP_HOST} ^(.+)$ [NC] RewriteRule ^(.*)$ https://www.%1/$1 [L,R=301] # ---- Cross-Domain Redirection (Optional) ---- # Uncomment and modify for domain migrations # RewriteCond %{HTTP_HOST} ^(www\.)?OLDDOMAIN\.com$ [NC] # RewriteRule ^(.*)$ https://www.YOURDOMAIN.com/$1 [L,R=301] # ---- 404 Error Handling ---- # CRITICAL: Redirect all 404 errors to homepage (prevents "not found" pages) ErrorDocument 404 https://www.YOURDOMAIN.com/ # ---- index.html Redirection ---- RewriteCond %{THE_REQUEST} /\index\.html [NC] RewriteRule ^index\.html$ / [L,R=301] # ---- CSS/JS Versioning ---- # NOTE: Comment out the lines below if using NGINX reverse proxy # (NGINX handles static file versioning more efficiently) RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L] # ---- Specific Page Redirects ---- # Add your 301 redirects below: # Redirect 301 /old-page.html https://www.YOURDOMAIN.com/new-page.html # Redirect 301 /another-old-page.html https://www.YOURDOMAIN.com/ # ---- Installation Checklist ---- # 1. Replace all instances of YOURDOMAIN.com with actual domain # 2. Replace "OLDDOMAIN" with actual old domain (if doing domain migration) # 3. Add specific page redirects as needed # 4. If using NGINX reverse proxy, comment out CSS/JS versioning section # 5. Test 404 handling by visiting non-existent page # 6. Test www/non-www redirects # 7. Test HTTP to HTTPS redirects