Six Presets for Common Apache Configurations
This htaccess file generator online covers six common Apache configuration needs. Basic gives a sensible starting point (directory index, no special routing) for a plain static or server-rendered site. Htaccess spa routing mode adds the rewrite rules a single-page app (React, Vue, Angular) needs, sending every request that isn't a real file or directory to your app's entry file so client-side routing works on a hard refresh or direct link. Htaccess wordpress rewrite rules mode adds the standard WordPress front-controller pattern, routing everything through index.php. Redirect-focused acts as a dedicated htaccess redirect generator, Security-focused, and Performance-focused are the same underlying rule set with a different emphasis for readability when you know which category of rule you're primarily configuring.
How to Use This .htaccess Generator
Pick a preset from the toolbar. Set WWW handling to force www, remove www, or leave it unchanged, this is an htaccess www redirect generator built into the same tool rather than a separate one. For Basic, Redirect-focused, Security-focused, and Performance-focused presets, set Directory index to your site's default file. For SPA routing, that same field becomes the SPA fallback file every non-file request routes to. Add Custom redirects as "from to" pairs, one per line, with an optional status code (defaults to 301), covering the htaccess https redirect case and any other from/to mapping. Toggle Force HTTPS, htaccess gzip compression, browser caching, apache htaccess security headers, and custom error pages independently of whichever preset you picked, results update automatically as you change any field.
What Each .htaccess Directive Does
An .htaccess file is mostly Apache's mod_rewrite, mod_deflate, mod_expires, and mod_headers modules configured through directives, each doing one specific job.
| Directive / Module | Purpose |
|---|---|
| RewriteEngine / RewriteCond / RewriteRule | The core pattern-matching and redirect/rewrite engine used for HTTPS redirects, www handling, custom redirects, and SPA/WordPress routing |
| mod_deflate (this htaccess gzip compression block) | Compresses text-based responses (HTML, CSS, JS, JSON) before sending them, reducing transfer size |
| mod_expires | Sets far-future cache headers on images and other static assets so repeat visitors reload the page faster |
| mod_headers (apache htaccess security headers) | Sets response headers like X-Frame-Options and Referrer-Policy that harden the site against common attacks |
SPA Routing vs. WordPress Routing
Both presets solve the same underlying problem, a URL that doesn't correspond to a real file on disk, but for different kinds of apps. SPA routing rewrites any request that isn't an existing file or directory to a static fallback file (typically index.html), letting your JavaScript router take over and render the right view client-side. WordPress routing instead rewrites everything through index.php, PHP's own routing (via WordPress's query and template system) decides what to render server-side on every request. Picking the wrong one won't just fail to help, a WordPress site given the SPA rule would serve static HTML instead of running PHP, and an SPA given the WordPress rule would try to execute a PHP file it doesn't have.