Free .htaccess Generator
Build a valid Apache .htaccess file in seconds. Configure redirects, force HTTPS, set error pages, enable compression, caching, and security — all wrapped in safe IfModule guards.
Domain & Redirection
Used for WWW and hotlink rules. Omit https:// and trailing slashes.
Custom Redirects
No custom redirects. Click "Add Redirect" to create a 301 or 302.
Custom Error Pages
Security
Comma or space separated. Supports individual IPs and CIDR ranges.
Performance
Custom Directives
Appended verbatim to the end of the file.
# Generated by InstantIndexer (https://instantindexer.com)
# Generated on 2026-06-20
# Apache .htaccess configuration — place in your website root.
# Always back up your existing .htaccess before replacing it.
<IfModule mod_rewrite.c>
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# Custom error pages
ErrorDocument 404 /404.html
# Security
Options -Indexes
ServerSignature Off
<Files ".ht*">
Require all denied
</Files>
# GZIP compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/json application/xml application/rss+xml
AddOutputFilterByType DEFLATE image/svg+xml font/woff font/woff2 application/font-woff
</IfModule>
# Browser caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
</IfModule>
.htaccess Generator: The Complete Guide for Apache Servers
An .htaccess generator produces a valid configuration file that Apache reads on every request. The .htaccess file lets you control URL redirects, force HTTPS, set up custom error pages, enable GZIP compression, configure browser caching, and lock down security — all without touching the main server config.
What Is the .htaccess File Used For?
The .htaccess file is a distributed Apache configuration file. When you create htaccess rules in the root directory, Apache applies them to that directory and every subdirectory underneath it. Most shared hosts use Apache, so this is the primary way site owners customize behavior.
Common uses include 301 redirects for moved pages, URL rewrites that turn ugly query strings into clean URLs, blocking malicious traffic by IP, and instructing browsers to cache static assets for faster repeat visits.
Core Directives This Generator Produces
- RewriteRuleThe workhorse of
mod_rewrite. Matches a requested URL pattern and either rewrites it internally or redirects the browser. - RewriteCondA condition that must be true before the following RewriteRule fires — used to detect HTTPS state, host name, or referring site.
- ErrorDocumentMaps an HTTP status code (404, 500) to a custom page so visitors see branded messaging instead of a default Apache error.
- AddOutputFilterByTypePart of
mod_deflate. Tells Apache to GZIP-compress responses of a given MIME type, shrinking transfer size. - ExpiresByTypeFrom
mod_expires. Sets a Cache-Control lifetime per file type so browsers reuse cached assets.
How to Use the Free .htaccess Generator
Toggle the features you need — force HTTPS, WWW preference, custom 301 redirects, error pages, security hardening, compression, and caching. The live preview on the right updates instantly as you change settings.
Every directive is wrapped in an <IfModule> guard so the file degrades gracefully on servers missing the relevant module. Once you are happy with the output, click Download to save it as .htaccessand upload it to your website root via FTP or your host's file manager.
Before You Replace Your .htaccess
- Download and keep a copy of your current
.htaccessfirst. - If you see a 500 error after uploading, rename the file to
.htaccess.bakto restore service instantly. - Test redirects in an incognito window to avoid cached 301s during development.
Frequently Asked Questions
An .htaccess file is a distributed configuration file used by Apache web servers to override server settings on a per-directory basis. It controls redirects, URL rewrites, access control, authentication, caching, compression, and many other behaviors without editing the main server configuration.
Upload the .htaccess file to the root public directory of your website (commonly public_html, htdocs, or www), where your homepage's index file lives. Apache applies rules to that directory and all subdirectories beneath it.
No. The .htaccess file is an Apache-specific configuration format. Nginx, Microsoft IIS (web.config), and other non-Apache servers ignore it. If your host uses Nginx or a reverse proxy in front of Apache, some directives may not behave as expected.
mod_rewrite (the RewriteRule directives) is more powerful and flexible, supporting conditional logic, query string manipulation, and pattern matching. mod_alias (Redirect and RedirectMatch) is simpler and faster for basic constant redirects. This generator uses mod_rewrite so you can chain and condition rules.
Yes. A syntax error in .htaccess typically results in a 500 Internal Server Error for every request in the affected directory. Always back up the existing file before replacing it, and remove or comment out lines one at a time to isolate problems if your site breaks.