Home › Developer Tools › Htaccess Generator

Htaccess Generator

Pick the features you want and get a clean, commented .htaccess file for Apache: HTTPS and www redirects, gzip or Brotli compression, browser caching, custom error pages, IP blocking, hotlink protection and basic security headers.

Last updated:

Quick start:

Site

Redirects

Performance

Custom error pages

Block IP addresses

Hotlink protection

Security & misc

Your .htaccess file


      

    Upload the file to your site's root folder (usually public_html) and name it exactly .htaccess. Keep a backup of any existing file first.

    Advertisement
    Advertisement

    How to use the Htaccess Generator

    1. Enter your domain and choose Apache 2.4 (most hosts) or 2.2.
    2. Tick the features you need, or start from a preset such as Basic site.
    3. Fine-tune cache lifetimes, error page paths, blocked IPs and hotlink settings.
    4. Read the warnings under the file; they flag risky or incomplete choices.
    5. Copy or download the file, upload it to your site root as .htaccess and test your pages.

    What each section does

    OptionApache moduleDirective usedEffect
    Force HTTPS / wwwmod_rewriteRewriteCond, RewriteRule [R=301]Permanent redirect to one canonical address
    HSTSmod_headersHeader always set Strict-Transport-SecurityBrowsers use HTTPS automatically on later visits
    Gzipmod_deflateAddOutputFilterByType DEFLATEText files are typically 60-80% smaller on the wire
    Brotlimod_brotliAddOutputFilterByType BROTLI_COMPRESSUsually a little smaller than gzip for text
    Browser cachingmod_expiresExpiresByTypeRepeat visitors reuse files instead of downloading them
    Error pagescoreErrorDocumentFriendly page instead of the server default
    Block IPsmod_authz_core (2.4)Require not ipListed addresses get 403 Forbidden
    Hotlink protectionmod_rewriteRewriteCond %{HTTP_REFERER}Other sites cannot embed your images or video
    Directory listingcoreOptions -IndexesFolders without an index file return 403

    Testing your .htaccess safely

    1. Download a backup of the current file before replacing it.
    2. Test redirects with a short HSTS time (or HSTS off) first: browsers remember HSTS and permanent redirects.
    3. Open http://, http://www. and https://www. versions of your homepage and check you land on one address in a single hop.
    4. Check compression and caching in your browser's developer tools: the Network tab shows content-encoding: gzip or br and the cache-control header.
    5. If the site shows a 500 error, restore the backup and add sections back one at a time.

    Apache 2.4 vs 2.2 access rules

    Apache 2.4 replaced Order, Allow and Deny with Require. Mixing the two styles in one file causes confusing results, so pick the version your host runs (almost all current hosts use 2.4). Blocking with <RequireAll> Require all granted / Require not ip …</RequireAll> lets everyone in except the listed addresses.

    Frequently asked questions

    What is an .htaccess file?

    It is a configuration file that the Apache web server reads from a folder of your site. Rules in it apply to that folder and everything below it, so you can add redirects, compression, caching and access rules without editing the main server configuration.

    Where do I put the .htaccess file?

    Upload it to the document root of your site, usually public_html or www, using FTP or your host's file manager. The name must be exactly .htaccess with the leading dot and no extension. Many file managers hide dot files, so turn on 'show hidden files'.

    Why do I get a 500 Internal Server Error after uploading?

    Usually a module is missing or a directive is not allowed on your host. This generator wraps rules in IfModule blocks to avoid that, but if it still happens, remove sections one by one to find the cause, and check that your host allows .htaccess overrides (AllowOverride).

    How do I force HTTPS with .htaccess?

    Use mod_rewrite: RewriteCond %{HTTPS} off followed by RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]. If your site sits behind Cloudflare or a load balancer, check the X-Forwarded-Proto header instead, otherwise the redirect can loop.

    Does .htaccess work on Nginx?

    No. Nginx does not read .htaccess files; the same features have to be written in the server block of the Nginx configuration. LiteSpeed and OpenLiteSpeed servers do read most Apache .htaccess rules.

    Will long browser caching break my updates?

    Visitors keep cached files until they expire, so after changing a CSS or JavaScript file they may see the old version. Change the file name or add a version query string (style.css?v=2) whenever you update a long-cached file; keep HTML at a short or zero cache time.

    Does .htaccess slow down my site?

    Slightly: Apache checks for .htaccess files in each folder on every request. On shared hosting this is normal and the effect is tiny. If you control the server, the same rules can go into the main configuration with AllowOverride None for the best speed.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.Nginx Config GeneratorBuild an nginx server block: static site, SPA, reverse proxy or PHP, with SSL, gzip and redirects.Robots.txt GeneratorBuild a robots.txt file with rules, sitemap lines and AI-bot blocking presets.HTTP Status CodesSearch every HTTP status code with plain-English meanings, causes, fixes and RFC references.Access Log AnalyzerAnalyze Apache and Nginx access logs: top URLs, IPs, status codes, bots and traffic charts.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.Random String GeneratorGenerate secure random strings and tokens in bulk with any length and character set.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.Gitignore GeneratorBuild a .gitignore from 50+ templates for languages, frameworks, IDEs and OS, merged and deduped.License GeneratorCreate a LICENSE file for MIT, Apache, GPL, BSD, ISC, MPL or Unlicense with your name and year.ULID GeneratorGenerate sortable ULIDs and UUID v7 in bulk, monotonic option, and decode their timestamps.Htpasswd GeneratorCreate .htpasswd entries with bcrypt, APR1-MD5 or SHA-1 for Apache and Nginx basic auth.Placeholder Image GeneratorCreate placeholder images in any size, color and text as PNG, JPG, WebP, SVG or data URI.Ads.txt GeneratorCreate or validate ads.txt and app-ads.txt files: seller lines, cert IDs and variables.Docker Run to Compose ConverterConvert docker run commands to docker-compose.yml, or a compose file back to docker run.Dockerfile GeneratorGenerate a production Dockerfile and .dockerignore for Node, Python, Go or a static nginx site.HTML Boilerplate GeneratorTick the options you need and get a clean HTML5 starter template with meta, OG tags and CSS reset.JSON to Zod SchemaInfer a Zod (or Yup) schema from sample JSON with optional, nullable and z.infer types.Linux Commands Cheat SheetSearchable Linux and bash command reference with flags explained, examples and copy buttons.LLMs.txt GeneratorBuild an llms.txt file for AI crawlers: summary and link sections, import from your sitemap.Nano ID GeneratorGenerate secure Nano IDs with custom alphabet, length and count, plus a collision calculator.OpenAPI / Swagger ViewerView OpenAPI 2/3 JSON or YAML as interactive API docs with validation and an endpoint list.package.json GeneratorFill a form and get a valid, npm-ready package.json with scripts, dependencies and checks.PKCE Code Challenge GeneratorGenerate an OAuth 2.0 PKCE code_verifier and S256 code_challenge, build auth URLs, verify pairs.README GeneratorFill in a form and get a polished README.md with badges, install, usage and license, live preview.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Commit Message GeneratorBuild Conventional Commit messages with type, scope, body, breaking change and issue refs.Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.Docker Compose GeneratorBuild a docker-compose.yml with a form: services, ports, volumes, env, healthchecks and presets.Dummy File GeneratorCreate test files of an exact size in KB, MB or GB with zeros, random bytes or text.OpenAPI ValidatorValidate OpenAPI 3.0/3.1 and Swagger 2.0 specs: schema errors, broken $refs, line numbers.Pivot Table MakerBuild pivot tables from CSV or Excel by drag and drop: sum, count, average, charts, export.SQL Query BuilderBuild SELECT queries visually: joins, filters, GROUP BY, ORDER BY and LIMIT, as clean SQL.Truth Table GeneratorType a logic expression and get its full truth table, minterms and canonical DNF/CNF.TypeScript PlaygroundWrite TypeScript with live type checking, see the compiled JavaScript and run it in your browser.Article Schema GeneratorCreate Article, BlogPosting or NewsArticle JSON-LD with headline, authors, dates and images.Event Schema GeneratorCreate Event JSON-LD with dates, venue or online location, tickets, organizer and performers.Google Search Query BuilderBuild advanced Google searches with site:, filetype:, intitle:, exact phrases and date operators.HowTo Schema GeneratorCreate HowTo JSON-LD with steps, tools, supplies, total time and cost, then copy it.HTML Email Template BuilderDrag and drop blocks to build a responsive, table-based HTML email with inline styles.Organization Schema GeneratorCreate Organization JSON-LD with logo, URL, contact points, address and social profiles.PIN GeneratorGenerate random 4, 6 or 8-digit PINs that avoid sequences, repeats, dates and common PINs.Product Schema GeneratorBuild Product JSON-LD with price, availability, brand, GTIN, ratings and reviews.Question Keyword GeneratorFind the questions people ask about a topic, grouped by who, what, why, how, can and more.Recipe Schema GeneratorCreate Recipe JSON-LD with ingredients, steps, prep and cook times, nutrition and ratings.Security Headers GeneratorPick HSTS, CSP, frame, referrer and permissions options and get Apache, Nginx, Netlify or Cloudflare config.SKU GeneratorBuild consistent SKUs from brand, category, size and color, then export every variant as CSV.Typography Scale GeneratorBuild a modular type scale from a base size and ratio, then copy CSS variables or a Tailwind config.WordPress Salt GeneratorGenerate fresh WordPress security keys and salts for wp-config.php, .env or Docker in one click.ANSI Color Code GeneratorStyle terminal text with 16, 256 or RGB colors and get escape codes for bash, Python, JS and C.Apache Virtual Host GeneratorCreate an Apache VirtualHost config with SSL, redirects, reverse proxy or PHP-FPM in seconds.Bash Prompt GeneratorDrag and drop a custom PS1 prompt for bash or zsh with colors, git branch and a live preview.Changelog GeneratorTurn Conventional Commit messages into a grouped Keep a Changelog Markdown file per version.cURL Command BuilderBuild curl commands from a form: method, headers, query, JSON or form body, auth and flags.Docker Compose to KubernetesConvert docker-compose.yml into Kubernetes Deployment, Service, ConfigMap and PVC manifests.Docker Compose ValidatorCheck a docker-compose.yml for YAML errors, schema mistakes, broken references and deprecated keys.Dockerfile LinterLint a Dockerfile for best practices: pinned tags, apt cleanup, non-root USER and layer count.Dockerignore GeneratorBuild a .dockerignore from Node, Python, Go and Java templates, plus your own entries.ESLint Config GeneratorGenerate a flat eslint.config.js for JavaScript, TypeScript, React or Node with rule presets.Git Branch Name GeneratorTurn a ticket ID and title into a clean, valid git branch name like feature/PROJ-12-add-login.
    See all 85 Code Generators & Builders →