# BEGIN Jays WordPress .htaccess
# ======================================================================================================================
# JAY'S WORDPRESS .HTACCESS
# Version: 2.11.25
# Released: 2026-11-30
# Repository: https://github.com/JayHoltslander/jays-wp-htaccess
#
# A production-tested .htaccess template for WordPress websites designed to maximize performance,
# harden security, and provide deep compatibility across Apache 2.2/2.4+, LiteSpeed, and reverse proxies.
#
# TABLE OF CONTENTS:
# ------------------
# 1. EMERGENCY & MAINTENANCE TOGGLES
# 2. DIRECTORY INDEX & SERVER OPTIONS
# 3. MIME TYPES & CHARACTER ENCODINGS
# 4. SECURITY HEADERS & CORS CONTROLS
# 5. PERFORMANCE, COMPRESSION & CACHING
# 6. SECURITY FILTERS & ACCESS RESTRICTIONS
# 6.1 Reverse Proxy & Cloudflare Normalization (REAL_IP & HTTPS)
# 6.2 Static Asset Performance Short-Circuit & Fast 404 (Bypass Deep Rewrite Scans)
# 6.3 Advanced Early-Drop Protection (Zero-PHP Overhead Scanner Mitigation)
# 6.4 Block Access to Hidden Files & Directories (ACME / SSL Whitelisted)
# 6.5 File Access Protections (Apache 2.4/2.2 Dual-Compatible: .ht*, wp-config, debug.log, xmlrpc)
# 6.6 Core WordPress Directory Hardening (install.php, wp-includes)
# 6.7 Image Hotlinking Defense (Optional)
# 6.8 Bot, Enumeration & Spam Query Filtering (Dynamic Requests Only)
# 6.9 8G Firewall v1.5 (Perishable Press Server-Level WAF)
# 6.10 IP-Based Access Control & Rate Limiting Examples
# 7. URL CANONICALIZATION, HTTPS & REDIRECTS
# 8. WORDPRESS FRONT CONTROLLER (Must remain at the very end of the file)
# ======================================================================================================================
# ======================================================================================================================
# 1. EMERGENCY & MAINTENANCE TOGGLES (OPTIONAL)
# ======================================================================================================================
# ----------------------------------------------------------------------------------------------------------------------
# REDIRECT ALL PAGES TO ROOT (EMERGENCY KILL-SWITCH)
# ----------------------------------------------------------------------------------------------------------------------
# Site under attack, database crashed, or undergoing major maintenance?
# Uncommenting this block will temporarily redirect all visitors to the root homepage (/) using a 302 (temporary) redirect.
#
#
# RewriteEngine On
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule .? / [R=302,L]
#
# ----------------------------------------------------------------------------------------------------------------------
# 301 REDIRECT ALL .SHTML FILES TO .HTML
# ----------------------------------------------------------------------------------------------------------------------
# Useful when migrating legacy server-parsed HTML sites (.shtml) to standard HTML pages without losing SEO rank.
#
#
# RewriteEngine On
# RewriteRule ^(.*)\.shtml$ https://www.example.com/$1.html [R=301,L]
#
# ======================================================================================================================
# 2. DIRECTORY INDEX & SERVER OPTIONS
# ======================================================================================================================
# ----------------------------------------------------------------------------------------------------------------------
# FALLBACK FOR INDEX.PHP
# ----------------------------------------------------------------------------------------------------------------------
# Specifies the priority order of default directory index files.
# If index.php is missing (e.g. during a WordPress core update), Apache will seamlessly attempt to serve MAINT-index.html
# from the same directory rather than throwing a generic server error or directory listing.
# Maintenance template example: https://codepen.io/j_holtslander/pen/KNgbMP
DirectoryIndex index.php index.html MAINT-index.html
# ----------------------------------------------------------------------------------------------------------------------
# BLOCK ACCESS TO DIRECTORIES WITHOUT A DEFAULT DOCUMENT (DIRECTORY BROWSING)
# ----------------------------------------------------------------------------------------------------------------------
# Prevents visitors and automated scanners from seeing a file directory index (file tree) if no default index document
# exists in that folder (e.g. /wp-content/uploads/ or /wp-content/plugins/).
# See: https://httpd.apache.org/docs/current/mod/mod_autoindex.html
Options -Indexes
# ----------------------------------------------------------------------------------------------------------------------
# PREVENT OVERZEALOUS 404 ERRORS FROM APACHE CONTENT NEGOTIATION (MULTIVIEWS)
# ----------------------------------------------------------------------------------------------------------------------
# Apache's MultiViews feature attempts to guess alternative file extensions (e.g. requesting /page matches /page.php).
# This frequently interferes with WordPress URL rewrite rules, causing unexpected 404 errors when a folder or file
# shares the same name as a WordPress page slug.
# See:
# * https://httpd.apache.org/docs/current/content-negotiation.html#multiviews
# * https://www.infomaniak.com/en/support/faq/605/redirect-and-url-rewrite-issues-multiviews-option-in-htaccess
Options -MultiViews
# ----------------------------------------------------------------------------------------------------------------------
# DISABLE SERVER-SIDE INCLUDES (SSI) & CGI SCRIPT EXECUTION
# ----------------------------------------------------------------------------------------------------------------------
# Hardens the environment by disabling legacy Server-Side Includes (.shtml) and direct CGI execution (.cgi, .pl).
Options -ExecCGI -Includes
# ----------------------------------------------------------------------------------------------------------------------
# REMOVE SERVER SIGNATURE FROM ERROR DOCUMENTS
# ----------------------------------------------------------------------------------------------------------------------
# Prevents Apache from appending the server software name, Apache version, OS, and port number to server-generated error pages.
# See:
# * https://httpd.apache.org/docs/current/mod/core.html#serversignature
# * https://techjourney.net/improve-apache-web-server-security-use-servertokens-and-serversignature-to-disable-header/
ServerSignature Off
# ----------------------------------------------------------------------------------------------------------------------
# SHOW THE ADMIN’S EMAIL ADDRESS IN APACHE ERROR MESSAGES (OPTIONAL)
# ----------------------------------------------------------------------------------------------------------------------
# If ServerSignature is on or custom error pages are configured, this sets the contact address shown to visitors.
#SetEnv SERVER_ADMIN email@isp.com
# ----------------------------------------------------------------------------------------------------------------------
# INCREASE MAXIMUM PHP UPLOAD & EXECUTION LIMITS (OPTIONAL)
# ----------------------------------------------------------------------------------------------------------------------
# Note: These php_value directives only work on servers running Apache with mod_php (prefork).
# On modern PHP-FPM / FastCGI servers (cPanel EA4, Plesk, Nginx/Apache hybrids), placing php_value here will cause a
# 500 Internal Server Error. Configure these in your .user.ini or php.ini instead if using PHP-FPM.
#
#php_value upload_max_filesize 64M
#php_value post_max_size 64M
#php_value max_execution_time 300
#php_value max_input_time 300
# ======================================================================================================================
# 3. MIME TYPES & CHARACTER ENCODINGS
# ======================================================================================================================
# ----------------------------------------------------------------------------------------------------------------------
# DEFAULT CHARACTER SET (UTF-8)
# ----------------------------------------------------------------------------------------------------------------------
# Forces UTF-8 encoding by default for all plain text and HTML responses.
# See: https://httpd.apache.org/docs/current/mod/core.html#adddefaultcharset
AddDefaultCharset utf-8
# Character Encodings for Specific File Extensions
# See: https://www.w3.org/International/articles/http-charset/
AddCharset utf-8 .atom \
.css \
.geojson \
.ics \
.js \
.json \
.jsonld \
.manifest \
.md \
.markdown \
.mjs \
.rdf \
.rss \
.topojson \
.vtt \
.webmanifest \
.xml
# Data Interchange Formats
AddType application/atom+xml atom
AddType application/geo+json geojson
AddType application/json json map topojson
AddType application/ld+json jsonld
AddType application/rss+xml rss
AddType application/vnd.geo+json geojson
AddType application/xml rdf xml
# JavaScript Modules & Scripts (RFC 9239 Standard: text/javascript)
# See: https://datatracker.ietf.org/doc/html/rfc9239
AddType text/javascript js mjs
# Web Application Manifest Files
# See: https://w3c.github.io/manifest/
AddType application/manifest+json webmanifest
# WebAssembly (Wasm) Binary Modules
# See: https://webassembly.github.io/spec/core/intro/introduction.html
AddType application/wasm wasm
# Media Files & Modern Image Formats (AVIF, WebP, JXL, HEIC/HEIF)
# See: https://calendar.perfplanet.com/2020/avif-has-landed/
AddType audio/mp4 f4a f4b m4a
AddType audio/ogg oga ogg opus
AddType image/avif avif avifs
AddType image/bmp bmp
AddType image/heic heic
AddType image/heif heif
AddType image/jxl jxl
AddType image/svg+xml svg svgz
AddType image/webp webp
AddType image/x-icon cur ico
AddType video/mp4 f4v f4p m4v mp4
AddType video/ogg ogv
AddType video/webm webm
# Web Fonts (RFC 8081 Standard: font/*)
# See: https://datatracker.ietf.org/doc/html/rfc8081
AddType font/woff woff
AddType font/woff2 woff2
AddType font/ttf ttf
AddType font/otf otf
AddType font/collection ttc
AddType application/vnd.ms-fontobject eot
# Augmented Reality Assets (USDZ for iOS Safari Quick Look)
# See: https://webkit.org/blog/8421/viewing-augmented-reality-assets-in-safari-for-ios/
AddType model/vnd.usdz+zip usdz
# Miscellaneous Document & Caption Types
AddType text/calendar ics
AddType text/markdown markdown md
AddType text/vcard vcard vcf
AddType text/vtt vtt
# Gzip Encoding for Pre-Compressed SVGZ Images
# See: https://davidwalsh.name/serve-svg-image
AddEncoding gzip svgz
# ----------------------------------------------------------------------------------------------------------------------
# FORCE SPECIFIC FILES TO DOWNLOAD INSTEAD OF OPENING IN BROWSER (OPTIONAL)
# ----------------------------------------------------------------------------------------------------------------------
# By mapping extensions to application/octet-stream, browsers will trigger a "Save File" download dialog.
# See: https://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/
#
# AddType application/octet-stream .csv
# AddType application/octet-stream .xls
# AddType application/octet-stream .doc
# AddType application/octet-stream .pdf
# ======================================================================================================================
# 4. SECURITY HEADERS & CORS CONTROLS
# ======================================================================================================================
# ------------------------------------------------------------------------------------------------------------------
# MIME SNIFFING PROTECTION (X-Content-Type-Options: nosniff)
# ------------------------------------------------------------------------------------------------------------------
# Prevents browsers from MIME-sniffing a response away from the declared content-type (e.g. executing user-uploaded
# images that contain embedded executable JavaScript).
# Note: "Header always set" guarantees the header is returned on all responses (including 403 blocks and 404s).
# See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
Header always set X-Content-Type-Options "nosniff"
# ------------------------------------------------------------------------------------------------------------------
# CLICKJACKING PROTECTION (X-Frame-Options: SAMEORIGIN)
# ------------------------------------------------------------------------------------------------------------------
# Prevents external malicious websites from embedding your site inside an
# ----------------------------------------------------------------------------------------------------------------------
# ALLOW CROSS-ORIGIN RESOURCE SHARING (CORS) FOR ALL ASSETS (OPTIONAL)
# ----------------------------------------------------------------------------------------------------------------------
# See:
# * https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
# * https://enable-cors.org/
# * https://stackoverflow.com/a/13871027/751570
#
#
# Header set Access-Control-Allow-Origin "*"
#
# ----------------------------------------------------------------------------------------------------------------------
# SEND CORS & CORP HEADERS FOR IMAGES
# ----------------------------------------------------------------------------------------------------------------------
# Needed when drawing cross-origin images to HTML5