the IT Hustle
ToolsField ManualAbout

.htaccess Generator

Build Apache .htaccess configuration visually. Add redirects (301/302), URL rewrites, CORS headers, gzip compression, browser caching rules, and custom error pages.

Domain
General
WWW:
Redirects
Error Pages
.htaccess Output
# Generated by The IT Hustle .htaccess Generator
# https://the-it-hustle.com/tools/htaccess-generator

# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirects
Redirect 301 /old-page /new-page

# Gzip Compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/javascript
  AddOutputFilterByType DEFLATE application/javascript application/json
  AddOutputFilterByType DEFLATE application/xml text/xml
  AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# Browser Caching
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 30 days"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType image/gif "access plus 30 days"
  ExpiresByType image/svg+xml "access plus 30 days"
  ExpiresByType text/css "access plus 30 days"
  ExpiresByType application/javascript "access plus 30 days"
</IfModule>

<IfModule mod_headers.c>
  Header set Cache-Control "max-age=2592000, public"
</IfModule>

# Custom Error Pages
ErrorDocument 404 /404.html

# Disable Directory Listing
Options -Indexes

# Security Headers
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set X-XSS-Protection "1; mode=block"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

Generates Apache .htaccess rules. Always test on a staging server before deploying.

How to Generate an .htaccess File

Build Apache redirects, caching, and security rules visually with The IT Hustle's free .htaccess Generator.

  1. 1
    Enter your domainType your domain name — it's woven into the rewrite conditions the generator produces.
  2. 2
    Toggle the essentialsEnable Force HTTPS, gzip compression, browser caching (with a configurable cache duration), CORS, hotlink protection, and directory listing control.
  3. 3
    Settle the www questionChoose to force www, remove www, or leave URLs as-is — enforcing one canonical form is good for SEO.
  4. 4
    Add redirects and error pagesCreate 301 or 302 redirects for moved pages and point error codes like 404 to custom error pages.
  5. 5
    Copy the fileCopy the generated rules — including a baseline of security headers — into the .htaccess file at your site's document root.

Frequently Asked Questions

A per-directory configuration file for the Apache web server. It controls redirects, rewrites, caching, compression, and access rules without touching the main server config — which is why it's the standard tool on shared hosting.

No — .htaccess is Apache-specific, and nginx ignores it by design. If your site runs on nginx, use our Nginx Config Generator to accomplish the same goals in nginx syntax.

301 means permanently moved — browsers cache it and search engines transfer the old URL's ranking to the new one. 302 is temporary — nothing is cached or transferred. Use 301 for restructures, 302 for short-lived situations like maintenance pages.

Even with an SSL certificate installed, visitors typing plain http:// land on the insecure version. The Force HTTPS rule rewrites every HTTP request to HTTPS at the server level, guaranteeing encrypted connections and avoiding duplicate-content issues.

A malformed .htaccess causes an immediate 500 error, so keep a backup of the previous file before uploading changes. If the site breaks, restore the backup — and test rules on a staging copy when possible.

Related Tools

Nginx Config GeneratorRobots.txt & Sitemap GeneratorHTTP Header Explorer