Points
3
Solutions
0
Apache .htaccess Configuration for XenForo 2 (No Cloudflare)
Always make a save of your .htaccess first or (rename .htaccess to .htaccess.old)
Overview
This document explains the Apache .htaccess configuration designed for a XenForo 2 installation running directly on Apache, with no Cloudflare in front.
Its purpose is to provide a clean, production‑ready setup with:
Direct HTTP ➝ HTTPS redirection
Proper XenForo front‑controller routing
Browser caching for static assets
Compression for text-based responses
Basic security headers
Environment Assumptions
Application: XenForo 2.x
Web server: Apache
Reverse proxy/CDN: None
Install location: Web root
HTTPS: Enabled in production
Included File
- .htaccess-no-cloudflare — template configuration for use without Cloudflare
Required Apache Modules
The configuration expects these modules to be available:
mod_rewrite
mod_headers
mod_expires
mod_deflate
What the Configuration Does
Redirects HTTP ➝ HTTPS
All HTTP requests are forced to HTTPS using a permanent redirect.Ideal when Apache directly handles public traffic and TLS.
Routes XenForo Through
The rewrite logic ensures:
Existing files load normally
Existing directories load normally
XenForo static paths bypass the router
All other requests go through index.php
Adds Long‑Lived Cache Headers
Static assets (images, JS, CSS, fonts) receive 1‑year caching.Dynamic asset endpoints also benefit:
css.php
js.php
Enables Compression
Compression applies to common text-based formats:- HTML
- CSS
- JS
- JSON
- XML
- SVG
- Fonts
Applies Basic Security Headers
Security headers include:
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy
Strict-Transport-Security
Content-Security-Policy
CSP is compatibility‑focused and should be tested with your add‑ons and embeds.
Disables Directory Listing
Included protections:- Options -Indexes
- Deny access to dotfiles (.*)
Pre‑Production Checks
Before deploying, verify:
RewriteBase / matches your install path
HTTPS virtual host is properly configured
No conflicting redirect layers
CSP is compatible with your external services
HSTS fits your SSL/redirect policy
Validation Checklist
After deployment, confirm:
HTTP correctly redirects to HTTPS
Friendly URLs work
Static assets load normally
css.php and
js.php deliver correct cache headers
Security headers appear on normal + error responses
Login / logout / admin features work
No redirect loops
No CSP‑related console errors
Final Note
This .htaccess file is a solid, modern baseline for Apache‑based XenForo deployments.However, it must be validated against:
- your SSL/HTTPS setup
- your installed add-ons
- your hosting stack
HTTPS behavior
Rewrite routing
CSP compatibility
As a bonus for members, download the .htaccess file for this tutorial.