Smart .htaccess Generator
Generate secure, SEO-friendly, and performance-optimized Apache .htaccess rules without writing code.
This tool generates Apache .htaccess rules for redirects, HTTPS enforcement, WWW canonicalisation, caching headers, compression and basic security hardening. Pick the behaviour you need and copy the directives. Rules apply only on Apache — Nginx uses an entirely different configuration syntax.
How to use
Start with a pack (optional)
Click the WordPress, SEO, Security or Performance pack for a recommended starting set, then fine-tune. Or build from scratch by toggling individual modules.
Enable & configure modules
Switch on the rules you need — HTTPS, www redirect, 301/302 redirects, security headers, GZIP, caching, bot and IP blocking — and fill in any paths or values. The preview updates live.
Review the validation
The validator flags duplicate redirect sources, self-referencing loops, repeated error codes and Apache-compatibility notes so you ship a clean config.
Copy or download
Copy the result or download the ready-named .htaccess file. Upload it to your site's root directory via FTP, cPanel or your host's file manager.
What you can build
Force HTTPS & canonical URLs
Send every visitor to one secure, canonical hostname with combined HTTPS + www 301 redirects — essential for SEO and avoiding duplicate-content penalties.
Harden your site
Add X-Frame-Options, X-Content-Type-Options, Referrer-Policy and Content-Security-Policy headers, disable directory listing and block dotfiles in one toggle.
Speed up delivery
Enable GZIP compression and browser-cache Expires headers to shrink payloads and reduce repeat requests — a direct Core Web Vitals win.
Manage redirects
Map old URLs to new ones with 301 (permanent) or 302 (temporary) redirects when restructuring a site, retiring pages, or running campaigns.
Block bots & IPs
Deny aggressive scrapers by user-agent and lock out abusive IP addresses with Apache 2.4 Require directives.
Optimise WordPress
Drop in the standard permalink rewrite block plus HTTPS, caching, GZIP, security headers and wp-config protection with one click.
Understanding .htaccess
What is .htaccess?
A per-directory Apache config file. Rules apply to the folder it lives in and all subfolders, take effect instantly with no server restart, and can be overridden deeper in the tree — powerful, but evaluated on every request.
Apache redirect guide
Use Redirect 301 for permanent moves (passes link equity), Redirect 302 for temporary ones, and mod_rewrite RewriteRule for pattern-based or conditional redirects like HTTPS and www canonicalisation.
Security best practices
Always send security headers, disable directory listing (Options -Indexes), block access to dotfiles and config files, and force HTTPS. Wrap header rules in <IfModule mod_headers.c> so they fail safe.
Performance optimisation
GZIP (mod_deflate) compresses text assets; Expires headers (mod_expires) let browsers cache static files. Together they cut bandwidth and round-trips, improving LCP and overall page speed.
SEO benefit: a single canonical, HTTPS, correctly-redirecting site consolidates ranking signals onto one URL, eliminates duplicate-content dilution, and the faster load times from GZIP + caching are themselves a ranking factor.
At a glance
- Rules generated
- Redirects, HTTPS enforcement, WWW canonicalisation, caching headers, compression and basic security hardening
- Server requirement
- Apache only. Nginx uses an entirely different configuration syntax and ignores .htaccess
- Placement
- In the directory whose behaviour you want to change
- Caution
- A malformed directive can return a 500 on every request — keep a backup before replacing a live file
Sources & references
- Apache HTTP Server Documentation — Official .htaccess reference, including when not to use it
Related tools
Frequently asked questions
Quick answers about this free online tool.
Last updated
