Xgenious
developer

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.

Free — No SignupRuns in BrowserData Never UploadedPopular tool

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
Features

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 It Works

How to use .htaccess Generator

01

Select rules to include

Toggle: force HTTPS, www redirect, browser caching, GZIP, security headers, custom error pages.

02

Configure options

For redirects, choose www → non-www or non-www → www. Set cache expiry per file type.

03

Copy and deploy

Paste the generated content into your .htaccess file in the web root (public/ or public_html/).

Format Comparison

Apache modules used by common .htaccess rules

Use caseApache module
URL rewriting & redirectsmod_rewrite
Force HTTPS / canonical hostmod_rewrite
Browser caching of static assetsmod_expires / mod_headers
GZIP compressionmod_deflate
Security response headersmod_headers
Custom error pagescore ErrorDocument
Directory & file access controlcore Options / Require
Troubleshooting

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.

500 error after savingDirective for disabled module

Check 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.

HTTPS redirect loops infinitelyMissing RewriteCond %{HTTPS} off

Add `RewriteCond %{HTTPS} off` before the redirect rule. Without it, Apache redirects the already-HTTPS request again, creating an infinite loop.

HSTS locks out HTTP-only siteStrict-Transport-Security on non-SSL server

Only 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.

Hotlink protection blocks your own imagesRewriteCond HTTP_REFERER not excluding own domain

Add your own domain to the whitelist: `RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com`. Also add `RewriteCond %{HTTP_REFERER} !^$` to allow direct URL access.

.htaccess has no effectAllowOverride None in httpd.conf

Apache 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.

Caching returns stale assets after deployBrowser serves old JS/CSS despite max-age change

Cache 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.

FAQ

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.

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.

Let's talk