Free .htaccess Generator — Apache Rules for Redirects, HTTPS & Security
An .htaccess file is an Apache server configuration file that controls URL rewrites, HTTPS enforcement, browser caching, GZIP compression, and security headers at the directory level. This generator produces ready-to-copy .htaccess blocks for the most common use cases without writing Apache syntax manually.
developer
Generate Apache .htaccess rules for redirects, HTTPS, caching, and security headers.
- Force HTTPS with a clean mod_rewrite 301 redirect
- www → non-www and non-www → www canonical redirect
- Browser caching headers via mod_expires for static assets
- GZIP compression via mod_deflate
- Security response headers: X-Content-Type-Options, X-Frame-Options, Referrer-Policy, HSTS
- Custom error pages and directory listing protection
- Every block wrapped in <IfModule> guards — missing modules are skipped, not fatal
Everything you need in one .htaccess Generator
HTTPS redirect generator
Produces a clean mod_rewrite rule that 301-redirects every HTTP request to HTTPS — the canonical way to enforce SSL across a whole site.
www / non-www canonical redirects
Pick a single canonical hostname and the generator writes the matching 301 redirect so search engines and users never see duplicate URLs.
Caching & GZIP for speed
Adds mod_expires caching headers and mod_deflate compression — two of the highest-impact, lowest-effort web performance wins.
Security headers
Outputs response headers aligned with the OWASP Secure Headers Project: X-Content-Type-Options, X-Frame-Options, and Referrer-Policy.
How to use .htaccess Generator
Select rules to include
Toggle: force HTTPS, www redirect, browser caching, GZIP, security headers, custom error pages.
Configure options
For redirects, choose www → non-www or non-www → www. Set cache expiry per file type.
Copy and deploy
Paste the generated content into your .htaccess file in the web root (public/ or public_html/).
Apache modules used by common .htaccess rules
| Use case | Apache module |
|---|---|
| URL rewriting & redirects | mod_rewrite |
| Force HTTPS / canonical host | mod_rewrite |
| Browser caching of static assets | mod_expires / mod_headers |
| GZIP compression | mod_deflate |
| Security response headers | mod_headers |
| Custom error pages | core ErrorDocument |
| Directory & file access control | core Options / Require |
How to fix common syntax errors
Most “invalid JSON” failures come from a small set of mistakes. Paste the failing JSON above, click Validate, and the tool points you at the exact line and column.
Directive for disabled moduleCheck Apache error_log (cPanel → Errors, or `/var/log/apache2/error.log`). Wrap all directives in <IfModule> blocks — missing modules are then skipped instead of crashing the site.
Missing RewriteCond %{HTTPS} offAdd `RewriteCond %{HTTPS} off` before the redirect rule. Without it, Apache redirects the already-HTTPS request again, creating an infinite loop.
Strict-Transport-Security on non-SSL serverOnly add HSTS after confirming HTTPS is fully working. Start with `max-age=300` (5 minutes) before committing to `max-age=31536000` — a wrong long-term HSTS blocks all HTTP access for a year.
RewriteCond HTTP_REFERER not excluding own domainAdd your own domain to the whitelist: `RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com`. Also add `RewriteCond %{HTTP_REFERER} !^$` to allow direct URL access.
AllowOverride None in httpd.confApache ignores .htaccess when `AllowOverride None` is set in httpd.conf or the VirtualHost block. Change to `AllowOverride All` (or the specific directives needed) and reload Apache.
Browser serves old JS/CSS despite max-age changeCache headers tell browsers how long to cache, but do not invalidate existing caches. Use fingerprinted filenames (`app.abc123.js`) or query strings (`?v=2`) to force browsers to request the new file.
Frequently asked questions
An .htaccess (hypertext access) file applies Apache web server configuration at the directory level without requiring access to the main `httpd.conf` server configuration. It controls URL rewriting and redirects, HTTPS enforcement, browser caching, GZIP compression, access authentication, IP-based access control, custom error pages, and security response headers — all scoped to the directory it sits in and all its subdirectories.
You might also need
.env File Generator
Generate a boilerplate .env file for Laravel, Next.js, Node.js, or Docker.
Cron Expression Builder
Build cron schedules visually and get the expression + plain-English explanation.
Color Contrast Checker (WCAG)
Check foreground/background color contrast for WCAG AA and AAA compliance.
SQL Formatter
Format and beautify SQL queries with consistent indentation and keyword casing.
Regex Tester
Test regular expressions against strings with live match highlighting.
JSON Formatter & Validator
Format, validate, and minify JSON instantly in your browser.
JWT Decoder
Decode and inspect JSON Web Token header, payload, and signature.
Base64 Encoder / Decoder
Encode and decode Base64 strings instantly in your browser.
Further reading
Authority documentation and specifications behind this tool.
Need this built into your product?
We design and build custom software — SaaS platforms, MVPs, AI agents, and web apps.
Custom SaaS Development
End-to-end SaaS — API, auth, billing, dashboard, deployment.
MVP Development
Working product in 6–8 weeks. Fixed price, committed timeline.
AI Agent Development
Custom AI agents and workflow automation for your stack.
Web App Development
Full-stack web apps built with modern frameworks and best practices.
Have a project in mind?
We turn ideas into production-ready software — SaaS, web apps, mobile, and AI agents. Fixed price. Committed timeline. No surprises.