Code Templates

Apache & nginx Settings

Serve static files directly by nginx

ac3 avi avif bmp bz2 css cue dat doc docx dts eot exe flv gif gz htm html ico img iso jpeg jpg js mkv mp3 mp4 mpeg mpg ogg pdf png ppt pptx qt rar rm svg swf tar tgz ttf txt wav woff woff2 xls xlsx zip webp

Additional nginx directives

# Redirect /index.html to /
location = /index.html {
return 301 $scheme://$host/;
}

# Caching and Compression
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml image/x-icon image/bmp image/webp image/jpeg image/png image/gif;
gzip_vary on;

# X-Content-Type-Options
add_header X-Content-Type-Options "nosniff" always;

# Handling versioned static files
location ~* ^(.+)\.(\d+)\.(ac3|avi|avif|bmp|bz2|css|cue|dat|doc|docx|dts|eot|exe|flv|gif|gz|htm|html|ico|img|iso|jpeg|jpg|js|mkv|mp3|mp4|mpeg|mpg|ogg|pdf|png|ppt|pptx|qt|rar|rm|svg|swf|tar|tgz|ttf|txt|wav|woff|woff2|xls|xlsx|zip|webp)$ {
try_files $uri $1.$3 =404;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "max-age=31536000, public";
}

# Handling non-versioned static files
location ~* \.(ac3|avi|avif|bmp|bz2|css|cue|dat|doc|docx|dts|eot|exe|flv|gif|gz|htm|html|ico|img|iso|jpeg|jpg|js|mkv|mp3|mp4|mpeg|mpg|ogg|pdf|png|ppt|pptx|qt|rar|rm|svg|swf|tar|tgz|ttf|txt|wav|woff|woff2|xls|xlsx|zip|webp)$ {
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "max-age=31536000, public";
}

CMS Settings

Universal .htaccess Template

# .htaccess Configuration Template
# Version: 3.2
# Date: 2024-12-19
# Description: Simplified template for static HTML + WordPress blog on PLESK Apache + NGINX
# Instructions: Replace YOURDOMAIN.com with actual domain name

# 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]

# ---- Index.html Redirection (Static HTML CMS) ----
# Redirect index.html to / (only for root level, not /blog/)
RewriteCond %{THE_REQUEST} /\index\.html [NC]
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteRule ^index\.html$ / [L,R=301]

# ---- WordPress Blog Protection ----
# Ensure WordPress in /blog/ directory works properly
# (WordPress has its own .htaccess rules in the /blog/ directory)

# ---- 404 Error Handling ----
# Redirect all 404 errors to homepage (except blog URLs)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^.*$ / [L,R=301]

# Fallback 404 document
ErrorDocument 404 https://www.YOURDOMAIN.com/

# ---- 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. Ensure WordPress .htaccess exists in /blog/ directory
# 5. Test 404 handling by visiting non-existent page
# 6. Test www/non-www redirects
# 7. Test HTTP to HTTPS redirects
# 8. Test index.html redirects (root level only)
# 9. Test WordPress blog functionality in /blog/ 

The Robots.txt File

User-agent: *
Sitemap: https://www.example.com/sitemap.xml
Sitemap: https://www.example.com/blog/post-sitemap.xml

Template head best practices

<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="$var(metaDescription)$">
    <title>$var(pageTitle)$</title>
    <link rel="canonical" href="https://www.NAME.com/$var(pageURL)$.html">

Open Graph for static template

<!--Open Graph Tags-->
<meta property="og:type" content="website">
<meta property="og:title" content="$var(pageTitle)$">
<meta property="og:description" content="$var(metaDescription)$">
<meta property="og:url" content="https://www.DOMAIN.com/$var(pageURL)$.html">
<meta property="og:site_name" content="SITE NAME">
<meta property="og:image" content="https://www.DOMAIN.com/assets/images/*.*">
<meta property="og:image:alt" content="CONTENT NAME">
<meta property="og:locale" content="en_US">

WordPress Files

Theme Injector

WP Theme Files

WP Additional CSS

Import Yoast Settings

Updated on July 16, 2025
Was this article helpful?

Related Articles