Developer Utilities · Free tool
.htaccess Generator
Build a custom .htaccess file online to enforce HTTPS redirects, Gzip, caching, and hotlink protection. Create error pages and 301 redirects instantly with no download.
# .htaccess generated by Free Tool Arena
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Custom redirects
Redirect 301 /old-url /new-url
# Enable Gzip compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>
# Browser caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/html "access plus 1 hour"
</IfModule>
# Custom error pages
ErrorDocument 404 /404.html
ErrorDocument 500 /500.htmlApache-only. Save as .htaccess in your site root. Test in a staging environment before pushing live — a misformatted .htaccess can take a site down (500 errors). For Nginx, the equivalent goes in your server block, not a per-directory file.
Advertisement
What it does
.htaccess is Apache HTTP Server's per-directory configuration file — a mechanism for changing server behavior without modifying the main httpd.conf file or restarting the server. Originally introduced in Apache 1.0 (1995), .htaccess remains the dominant configuration interface for shared-hosting environments where tenants don't have access to the main server config. Common uses: HTTPS redirects (force all traffic to secure), www-vs-non-www enforcement (canonical URL for SEO), Gzip / Brotli compression, browser caching headers (cache static assets long-term), custom error pages (404, 500), hotlink protection (prevent other sites embedding your images), 301 redirects (permanent URL changes preserving SEO juice), and IP / referer-based access control.
The generator outputs a properly-formatted .htaccess file based on your selected features: tick the boxes for the rules you want enabled, configure parameters (redirect mappings, cache durations, allowed/blocked IPs), and copy the result into your /public_html/.htaccess file (or wherever your site root is). Important warning: a malformed .htaccess takes the ENTIRE site down with a 500 Internal Server Error. Always test changes in a staging environment or a branch URL before deploying to production. Keep a known-good backup of your current .htaccess before making changes. Apache caches .htaccess parsing per request, so changes take effect immediately on next request — no server restart needed.
When .htaccess is the right tool: shared hosting where you don't control the main server config (most cPanel-based hosts, GoDaddy, HostGator, Bluehost, SiteGround shared plans). When it's NOT the right tool: dedicated servers or VPS where you have full server access (.htaccess is slower than main config because Apache has to read every directory's .htaccess on every request — main config is parsed once at startup), Nginx servers (Nginx doesn't support .htaccess; equivalent rules go in nginx.conf server blocks), Caddy or other modern web servers (their own config formats), and modern static-site hosts (Netlify, Vercel, Cloudflare Pages — those use _redirects files, vercel.json, or UI-based config instead). For most modern deployments, .htaccess is a legacy tool; it remains widespread because of shared hosting's long tail.
Embed this tool on your siteShow snippetHide
Paste this snippet into any page. Loads on-demand (lazy), no tracking scripts, and sized to most dashboards. Replace the height to fit your layout.
<iframe src="https://freetoolarena.com/embed/htaccess-generator" width="100%" height="720" frameborder="0" loading="lazy" title=".htaccess Generator" style="border:1px solid #e2e8f0;border-radius:12px;max-width:720px;"></iframe>How to use it
- Tick which features you want: HTTPS redirect, www enforcement, Gzip, caching, error pages, hotlink protection.
- For 301 redirects, enter old-url and new-url pairs (one per line).
- For caching, set durations per file type (CSS/JS often 1 year; HTML often 1 hour).
- Copy the generated config and save as .htaccess in your site root (note the leading dot).
- Test in staging first — malformed .htaccess produces 500 errors that take the whole site down.
- Keep a backup of your previous .htaccess before deploying changes.
When to use this tool
- Shared hosting (cPanel, GoDaddy, HostGator, Bluehost) where you don't have main server config access.
- Quick HTTPS / www-vs-non-www enforcement on legacy Apache sites.
- Setting up 301 redirects for changed URLs (SEO preservation).
- Compression and caching headers without server restart.
- Hotlink protection on image/asset folders.
When not to use it
- Nginx servers — .htaccess is Apache-specific; Nginx ignores it. Configure server blocks in nginx.conf instead.
- Modern static-site hosts (Netlify, Vercel, Cloudflare Pages) — use their native config (_redirects, vercel.json, _headers).
- Dedicated servers or VPS with main config access — modify httpd.conf or vhost files for better performance.
- Production deployments without staging testing — malformed .htaccess takes the site down with 500 errors.
Common use cases
- Verifying a number or output before passing it on
- Quick generation during a typical workday
- Pre-decision sanity-check on inputs and outputs
- Educational use — demonstrating the underlying concept
Frequently asked questions
- Does this work for Nginx?
- No — .htaccess is Apache-specific. For Nginx, the equivalent rules go in your server block in nginx.conf. The intent is the same; the syntax differs significantly. There are .htaccess-to-nginx converters (online tools, winginx) that translate common rules — useful when migrating from Apache to Nginx hosting.
- What if my changes take the site down?
- Quick fix: rename or delete the .htaccess file via FTP / hosting panel — Apache will fall back to default behavior and the site comes back. To debug: check your hosting panel error logs for the specific syntax error, or comment out rules one by one. Always make changes via FTP/SSH where you can quickly revert; some hosting panels don't show the file readily.
- How does .htaccess compare to nginx.conf?
- Functionally similar but architecturally different. .htaccess: per-directory, parsed on every request (slower, slight performance hit), changes take effect immediately. nginx.conf: server-wide, parsed at startup (faster), requires nginx reload for changes. For high-traffic sites, server-config (Apache main config or nginx.conf) is preferred over .htaccess for performance reasons. .htaccess survives because shared-hosting tenants typically don't have main config access.
- What's the most common .htaccess use?
- WordPress sites: pretty-permalinks rewrite rules (almost universal). Static sites: HTTPS redirect, www-vs-non-www canonical enforcement, Gzip compression, browser caching headers. E-commerce sites: 301 redirects for renamed products, country-specific TLD redirects. Generally: anything that needs to happen at the request-routing layer before the application processes the request.
- Will Apache stop supporting .htaccess?
- No, .htaccess is core to Apache and not going anywhere. Performance criticism is real but the convenience for shared-hosting environments keeps it relevant. Apache 2.4+ added more granular AllowOverride directives so server admins can permit some .htaccess uses while restricting others. The trend is fewer features in .htaccess, not removal.
- Should I use .htaccess for security?
- For basic measures (deny IP ranges, password-protect directories with AuthBasic, prevent directory listing), yes — it's effective. For serious security (DDoS protection, application firewalling, malware scanning), use a dedicated WAF (Cloudflare, Sucuri, AWS WAF). .htaccess can't handle modern attack patterns; pair it with a CDN/WAF for production sites.
Advertisement
Learn more
Guides about this topic
- Using Our Tools · GuideHow to generate QR codesMake QR codes for URLs, WiFi, vCard, or text. Learn error correction and sizing, then generate your QR code online free with no sign-up in seconds.
- Using Our Tools · GuideHow to create a strong passwordGenerate a strong password instantly online for free. Build high-entropy passphrases following NIST 2026 rules with no download needed.
- Developers & Technical · GuideHow to encode and decode Base64Understand the 3-to-4 mechanic and 33% overhead for standard, URL-safe, and MIME Base64. Free online reference to avoid common mistakes, no download needed.
- Design & Media · GuideHow to choose a color paletteBuild accessible color palettes using HSL theory, monochromatic to triadic schemes, WCAG contrast checks, and dark mode tips. Free, no-download guide.
- Developers & Technical · GuideHow to use JWT tokens securelyImplement secure JWT authentication by choosing RS256, setting expiration, using httpOnly cookies, and preventing 'alg: none' attacks in your browser for free.
- Design & Media · GuideHow to design a faviconCreate favicons that render perfectly from 16×16 to 512×512 with dark mode support. Learn the right HTML tags and web manifest setup free online.
Explore more developer utilities tools
- Port Number LookupSearch over 140 well-known TCP and UDP ports by number or service name. Free online reference tool with no sign-up, covering web, mail, DNS, and more.
- Test Credit Card NumbersReference table of canonical test card numbers from Stripe, Adyen, and Braintree sandbox docs. Plus Luhn validator + network detector.
- IPv6 Expander & ShortenerFormat IPv6 addresses to canonical form, handling zone IDs and prefixes, instantly online—free tool with no registration required.
- Htpasswd GeneratorCreate .htpasswd lines for Apache or nginx basic auth with browser-only SHA hashing instantly. Includes config snippets and a free online tool with no registration.
- Chmod CalculatorCalculate Unix file permissions: octal (755, 644) ↔ symbolic (rwxr-xr-x) ↔ rwx checkboxes. Covers setuid, setgid, sticky bit. With presets.
- Excel Formula ExplainerPaste any formula and get a plain-English breakdown of 60+ functions online free—no sign-up required, in your browser.