Web Analytics

 Htaccess Generator

Use this free htaccess generator to create Apache rules for HTTPS, www, file and directory redirects, custom error pages, IP access, bot filtering, security headers, caching and Gzip. Add password protection and generate a bcrypt .htpasswd file entirely in your browser. Preview, copy or download your configuration without uploading your inputs.

Before deploying: back up your current .htaccess and test on staging. This generator targets Apache 2.4+, not Nginx. Your host must allow the selected directives through AllowOverride. Merge with existing rules; do not blindly replace WordPress or application configuration.
Domain & redirects
Required for HTTPS, www redirects or hotlink protection. Enter a hostname without a path or port.

HTTPS uses the exact domain above when no www preference is selected. Rules assume Apache terminates TLS directly. Behind a reverse proxy or CDN, ask your host for its trusted HTTPS detection to avoid redirect loops.

Custom redirects

Choose an exact file/page or a directory including its subpaths. Paths are case-sensitive and start at the website root. Directory redirects preserve the remaining path. Exact rules run first, then the most specific directory. Encode spaces as %20; double slashes are not supported. Queries are kept unless the destination supplies one.

Security & access

Enable HSTS only after HTTPS is working reliably. It does not include subdomains or preload. Framing protection may break third-party embeds. File blocking leaves /.well-known/ available for certificate validation.

Password protection

This path is only written into the output; no server file is created. Store .htpasswd outside the public document root. Always use HTTPS with Basic authentication.

Bcrypt cost 12, random salt, processed entirely in this browser using a bundled library. Passwords and hashes are never added to copy history. Generating a new entry replaces the previous entry.

IP access & bot filtering

Comma or newline separated IPv4/IPv6. A nonempty allow list denies everyone else; blocked addresses always win. Behind a proxy, configure trusted client IP handling with your host. You can lock yourself out.

Literal, case-insensitive matching. No blanket search-engine block is enabled. User agents can be forged; this is not authentication.

Error pages & directory index

Optional local paths, for example /errors/404.html. Files must exist. Local error documents keep the original HTTP error status.

Space-separated filenames. Leave blank to keep your host's defaults. SPA fallback still requires index.html.

Compression & caching

Custom duration overrides the preset (maximum one year). Default extensions do not include HTML. Never publicly cache personalized responses. Version assets before enabling long lifetimes.

Hotlinks & application routing

Allows your domain, its www variant and empty referrers. Referrers can be spoofed; this is bandwidth protection, not authentication.

Leave blank to block all external referrers. Entries match the domain and its subdomains, not lookalike domains.

Leave blank to return HTTP 403. A local replacement must exist and is excluded from the hotlink rule.

For root-hosted static apps only. Existing files, directories and /.well-known/ are excluded. Do not combine with WordPress/PHP front-controller rules. Custom redirects and SPA routing assume the file is at the document root.

Local .htpasswd output

The hash is sensitive too. Copy history is disabled for this entire tool; nothing is stored in localStorage or sent to the server.

Required modules are named in the output. Optional module sections are wrapped in <IfModule> and will not run if the module is unavailable. Check your host's configuration before deployment.

⭐ Htaccess Generator: Apache Configuration Guide

This htaccess generator builds a downloadable Apache configuration from the options you choose. An .htaccess file applies per-directory rules on servers that allow overrides. This tool creates root-level rules for Apache 2.4 or newer; it does not configure Nginx or change your hosting settings.

⚙️ Generate an .htaccess file step by step

  1. Select only the options your website needs. Enter your real domain for HTTPS, www redirects or hotlink protection.
  2. Add exact old and new paths for page redirects. Choose 302 while testing and 301 for permanent moves.
  3. Review the live preview, validation errors and deployment warnings.
  4. Copy the result or download .htaccess. Back up the existing file and merge carefully on staging first.
  5. Test redirects, assets, login pages and error responses before deploying to production.

🔁 Example: HTTPS and a non-www domain

For example.com, select Force HTTPS and Remove www. Both http://www.example.com/page and http://example.com/page redirect to https://example.com/page. Paths and query strings are preserved. These rules assume that Apache itself handles HTTPS; a reverse proxy needs host-specific trusted proxy configuration.

🔎 Example: redirect an old page

Enter /old-page as the source and /new-page as the destination. Only that exact path matches: /old-page/child is not redirected. A request to /old-page?ref=email keeps the query string, unless your destination provides a replacement query. Encode spaces in paths as %20. Avoid redirect chains; the generator rejects duplicate sources and detectable local loops, including loops through www/non-www variants when hostname or HTTPS redirects are enabled. Double slashes in source and destination paths are rejected, including URL-encoded variants, because Apache normally merges them. The generator cannot inspect redirects on other servers.

RewriteEngine On
RewriteRule "^old-page$" "/new-page" [R=301,END,NE]

📁 Redirect a directory and its subpaths

Select Directory and subpaths, enter /old-folder and /new-folder. Requests to /old-folder/photos/my%20photo.jpg?size=large redirect to /new-folder/photos/my%20photo.jpg?size=large, preserving the encoded suffix and query. Destinations may be external HTTP(S) URLs but cannot contain a query or fragment in directory mode. Root-level directory moves are not supported. Exact redirects run before directory rules, with the longest matching directory first. The generator checks detectable cycles between both kinds of rules, but existing server rules can still cause loops.

🔐 Password protection and local .htpasswd generation

Enable Basic authentication for the entire site or one filename, such as private.html. Supply an absolute deployment path to a password file outside the public document root, for example /home/account/private/.htpasswd. Enter a username and password and choose Generate .htpasswd locally. A bundled BSD-licensed bcryptjs 3.0.2 library hashes the password in your browser with a random salt and cost 12; no hashing request is sent to the server. The output uses Apache's $2y$ bcrypt format and can be copied or downloaded as a single-entry password file.

Passwords must be 8-72 UTF-8 bytes to avoid bcrypt's silent truncation, and usernames cannot contain colons or line breaks. Generating another entry replaces the previous output. Merge entries manually if you need multiple users, taking care not to duplicate usernames. The password field is cleared after successful generation. Changing credentials or choosing Clear invalidates any pending result. Copy history is disabled for this whole tool; passwords and hashes are not persisted to localStorage. Always serve Basic authentication over HTTPS. Apache needs mod_auth_basic, mod_authn_file and mod_authz_user.

🚧 IP allow lists, block lists and bot filtering

Enter comma- or newline-separated IPv4/IPv6 addresses or CIDR ranges, such as 192.0.2.10, 198.51.100.0/24 or 2001:db8::/32. A nonempty allow list denies everyone not listed; blocks take precedence even over allowed addresses. When password protection is enabled, allowed visitors must still authenticate. These rules use Apache 2.4 Require directives, not legacy Order/Allow/Deny syntax. Behind a proxy, the host must configure trusted client IP handling before these rules are useful. Keep a recovery path so you do not lock yourself out.

Bot filtering blocks literal, case-insensitive user-agent substrings that you specify. It is opt-in and does not automatically block search engines. Clients can forge user agents, so these checks are only a traffic filter, not a security boundary.

📄 Custom error pages and default directory pages

Set local error documents for HTTP 400, 401, 403, 404 and 500, for example /errors/404.html. Use existing root-relative files, not external redirects, to retain the original error status. Test that IP restrictions, Basic authentication and rewrite rules do not block the error document itself. The default directory setting accepts an ordered list such as index.html index.php. The first existing filename is served. Leaving it blank keeps your host's defaults; SPA fallback still targets index.html.

🛡️ Security headers and file access

MIME-sniffing protection, same-origin framing and a referrer policy add focused browser protections. File-access rules deny dotfiles, hidden directories and common configuration, database, log and backup filenames. The public /.well-known/ directory remains available for certificate validation, but hidden and sensitive files inside it are still blocked. These patterns are not a complete secret scanner: keep credentials and private backups outside the document root.

HSTS instructs browsers to use HTTPS for one year after receiving the header over HTTPS. Enable it only when you can maintain valid HTTPS. This generator deliberately omits includeSubDomains and preload. Hiding the server signature affects generated error pages, not the server's HTTP Server header.

🚀 Gzip and browser caching

Gzip compresses text-based responses using mod_deflate and mod_filter. Browser caching matches the file extensions you select, with CSS, JavaScript, images and fonts as defaults. Choose a preset or a custom duration in minutes, hours, days, weeks or 30-day months, up to one year. Public caching allows shared caches; private caching restricts storage to the browser. Must-revalidate requires validation when a cached response becomes stale, not on every request. Password protection requires private caching in this generator.

The generated rules use mod_expires and mod_headers. For example, 30-day caching reduces repeat downloads, while versioned asset names such as app.v2.css deliver updates. Do not publicly cache personalized HTML, PHP or JSON responses. Optional module blocks are skipped if their modules are unavailable; verify response headers to confirm that each feature is active.

🖼️ Hotlink protection and SPA fallback

Hotlink rules protect the extensions you select while allowing your domain, its www counterpart and requests without a referrer. Leave the referring-domain list blank to block all external referrers, or specify only the domains and subdomains to block. You can return HTTP 403 or redirect to an existing local replacement image or external HTTPS image. A local replacement is excluded from the hotlink check to prevent a loop. This may affect legitimate embeds and does not stop clients that forge referrers.

The single-page application option rewrites missing routes to an existing index.html, while leaving real files, directories and certificate-validation paths alone. Enable it only for a root-hosted static app, not alongside WordPress or another front controller.

⚠️ Hosting requirements and safe deployment

Place the file at the website's document root. Your host must enable the required modules and permit FileInfo, Options and/or Indexes overrides for the features selected. Missing rewrite support or forbidden directives can cause HTTP 500 errors. Restore the backup and read the Apache error log if this happens. Keep application-managed blocks intact and review rule order: access restrictions come first, then canonical and custom redirects, hotlink checks and finally SPA fallback.

All configuration inputs and password hashing are processed locally. This tool does not upload your inputs or write files to your server. The site's shared copy-history feature is disabled on this tool, including for generated hashes. Downloads are saved to your device; deploy the reviewed files yourself after testing.


This tool is also known as

  • htaccess file generator online
  • apache htaccess configuration generator
  • htaccess https redirect generator
  • htaccess 301 redirect generator
  • generate htaccess security and cache rules

Frequently Asked Questions

It creates Apache 2.4+ rules for file and directory redirects, password protection, IP access, bot filtering, error pages, directory indexes, headers, caching, Gzip, hotlink protection and SPA routing. It also generates a bcrypt .htpasswd entry locally.

Place it in the document root of your website, often public_html. These redirect and SPA rules assume root-level hosting. Back up and merge your existing configuration rather than replacing it blindly.

No. Nginx does not read .htaccess files. This generator is specifically for Apache 2.4 or newer with appropriate modules and AllowOverride permissions.

Enter your domain, enable Force HTTPS and choose Remove www. The generator combines protocol and hostname checks. The rules assume Apache terminates TLS directly; reverse proxies and CDNs require trusted, host-specific HTTPS detection.

Use 301 for a permanent move and 302 for a temporary move or initial testing. Browsers and search engines can cache permanent redirects, so test carefully before choosing 301.

Yes. The source matches an exact path, without a query string. Existing query parameters are preserved unless the destination supplies its own query string. Encode spaces as %20 and use a complete HTTP(S) URL for external destinations.

It rejects self redirects and circular chains on your configured domain, including www/non-www variants when HTTPS or hostname redirects are enabled. Double slashes in paths, including URL-encoded variants, are rejected because Apache normally merges them. Redirects on other servers or in existing configuration cannot be inspected.

You can carefully merge compatible security, caching and redirect rules with existing configuration. Preserve the WordPress-managed block and do not enable the static index.html SPA fallback. Test your permalink and login routes.

Only enable HSTS after HTTPS and your certificate work reliably. Browsers remember the requirement for one year after receiving the header over HTTPS. The generated header does not include subdomains or request preload registration.

Your host may disallow a directive or lack a required module. Restore your backup and inspect the Apache error log. Ask your host about AllowOverride FileInfo, Options and Indexes and the modules named in the output.

Optional features are wrapped in IfModule blocks and are skipped when the relevant module is missing. Check mod_deflate, mod_filter, mod_expires and mod_headers with your host, and inspect real response headers. Proxies and existing configuration can also affect results.

The dotfile rule exempts the public .well-known directory so normal ACME validation files remain accessible. Other hidden files and sensitive filename extensions are still denied. Always test renewal paths with your hosting setup.

Yes, for root-hosted static apps with an existing index.html. Missing routes are rewritten to index.html; real files, directories and .well-known paths are excluded. Review API and missing-asset behavior, and avoid combining this with another front controller.

No. It checks referrers for selected extensions, allowing your domain, its www counterpart and empty referrers. Optionally block only specified domains or redirect to a replacement image. Referrers can be forged, so this is not authentication.

All generation and bcrypt hashing happen locally in your browser. Inputs, passwords and hashes are not uploaded or saved to localStorage. Copy history is disabled for this tool. Downloads are saved to your device; you deploy the files yourself.

An exact redirect matches only one path. A directory redirect includes all subpaths and preserves their encoded suffix and query string. Exact redirects run first, followed by the most specific directory. Directory destinations cannot contain a query or fragment.

Enter a username and password and click Generate .htpasswd locally. The bundled bcrypt library creates a random-salted cost-12 hash in your browser. Copy or download the single entry, then place the file outside your public document root and use its absolute path in AuthUserFile.

Bcrypt only processes up to 72 UTF-8 bytes. The generator rejects longer passwords instead of silently truncating them. Multibyte characters use more than one byte. Passwords must be at least eight bytes, and the field is cleared after hashing.

Yes. Enable password protection and enter a single filename, such as private.html. Leaving the filename blank protects the entire site. Basic authentication needs HTTPS and a deployed password file; it is not activated by merely downloading the generated configuration.

Yes. A nonempty allow list denies all other addresses, and matching blocked addresses always win. IPv4, IPv6 and CIDR ranges are supported. With password protection enabled, allowed clients must also authenticate. Verify client-IP handling behind proxies to avoid locking yourself out.

Yes. Use an existing root-relative file for error 400, 401, 403, 404 or 500. Local ErrorDocument paths preserve the original status. Make sure authentication, access rules and rewrites do not block the error page. External error-page redirects are deliberately not offered.

Yes. Set comma-separated extensions and choose a preset or a duration in minutes, hours, days, weeks or 30-day months, up to one year. Select public or private caching and optionally must-revalidate. Password-protected configurations require private caching.

No. Enter the specific literal user-agent names you want to block and enable the filter. Matching is case-insensitive. It is not authentication because user agents can be forged.

Our web tools

  • Convert URLs to HTML Links
    Turn plain URLs, www addresses and emails into clickable HTML links with target, rel and custom link text
  • URL cleaner
    Clean, normalize, and sanitize URLs in bulk — remove UTM, fbclid, gclid and other tracking parameters
  • URL parser
    Parse URL structure, query values, tracking parameters, and generate a clean URL