Skip to content

Menu

.htaccess Generator

Generate Apache .htaccess rules for redirects, HTTPS, caching, and security.

Runs entirely in your browserDevOpsFree, no sign-up
Loading tool

01What is .htaccess Generator?

On shared hosting you often can't touch the main Apache config, but you can drop a .htaccess file in your document root. The catch is that one bad line takes the whole site down with a 500 error. This generator builds the file from toggles and short forms, with a # comment heading each block so you can see what does what. The directives come from the Apache HTTP Server 2.4 documentation for mod_rewrite, mod_alias, mod_headers, mod_deflate and mod_authz_core. Force HTTPS adds a mod_rewrite 301 whenever %{HTTPS} is off. The www setting redirects to either the www or the bare host. You can add any number of 301 or 302 redirects as mod_alias Redirect lines. A source without a leading slash gets one, and a path with spaces is wrapped in quotes. Custom ErrorDocument lines map status codes to your own pages. CORS adds Access-Control-Allow-Origin, Methods and Headers through mod_headers. Cache rules set a Cache-Control max-age per file extension. You can type extensions as jpg, png or jpg|png, and a duration that isn't a whole number of seconds is dropped. Blocking IPs uses Apache 2.4 syntax, a RequireAll block with Require not ip lines, instead of the old Order and Deny form. Lines that aren't IP addresses or CIDR ranges are ignored, so they can't sneak in other directives. Hotlink protection returns 403 for image requests whose Referer is another site, while still allowing empty referers. Options -Indexes turns off directory listings, the Gzip option compresses text, JSON, XML and SVG responses, and a free-text box takes anything else. Here's an example. Add a redirect from old-page to new-page as a 301. You get Redirect 301 /old-page /new-page, with the missing slash added for you. We loaded the output with every section switched on into a stock Apache 2.4 container. The redirects, the www redirect and the hotlink 403 all behaved as expected, with no config errors. Now the limits. It writes Apache syntax only, so it does nothing for Nginx or LiteSpeed-specific features. Force HTTPS checks %{HTTPS}, which loops behind a proxy or CDN that ends TLS. Redirect matches by prefix, not exact path.

Web developers on Apache shared hosting who need redirects, HTTPS, caching or IP blocks in .htaccess without memorising mod_rewrite syntax. The tool runs entirely in your browser, so your data never leaves your device.

02How to use .htaccess Generator

  1. Tick Force HTTPS and choose a www setting if you need them.
  2. Add redirects (old path, new path or full URL, 301 or 302) and error pages.
  3. Fill in CORS Headers, caching, blocked IPs and hotlink protection as needed.
  4. Review the generated file in the preview.
  5. Copy it into the .htaccess file in your document root, then test a few URLs.

03Worked examples

Input: Default settings (only Disable Directory Listing on)
Result: # Disable Directory Listing Options -Indexes
Input: Force HTTPS on; WWW redirect: non-www; directory listing off
Result: # Enable Rewrite Engine RewriteEngine On # Force HTTPS RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Redirect to non-www RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Input: Redirects: 301 old-page -> new-page; 302 /my file.html -> https://example.com/x
Result: # Redirects Redirect 301 /old-page /new-page Redirect 302 "/my file.html" https://example.com/x
A leading / is added to relative paths, and a path containing a space is wrapped in quotes. (The output also starts with RewriteEngine On.)
Input: Cache rule: extensions ".jpg, png|webp", 31536000; second rule css with duration "1 week"; Blocked IPs: 203.0.113.5, 198.51.100.0/24, "evil; Require all denied"
Result: # Cache Control <IfModule mod_headers.c> <FilesMatch "\.(jpg|png|webp)$"> Header set Cache-Control "max-age=31536000, public" </FilesMatch> </IfModule> # Block IPs (Apache 2.4) <RequireAll> Require all granted Require not ip 203.0.113.5 Require not ip 198.51.100.0/24 </RequireAll>
A duration has to be a whole number of seconds, so the "1 week" rule is dropped, and a line that isn't an IP or CIDR range is ignored.
Input: Hotlink protection on; domain https://www.example.com/images
Result: # Hotlink Protection RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https?://(www\.)?example\.com(:\d+)?(/|$) [NC] RewriteRule \.(jpg|jpeg|png|gif|svg|webp|avif)$ - [F,NC,L]
The scheme, www. and path are removed from the domain. Requests with an empty referrer are still allowed.

04Common use cases

  • Adding 301 redirects after renaming pages so old links and search results land on the new URLs
  • Forcing HTTPS and picking one canonical host, www or bare domain, on shared hosting
  • Setting a one-year Cache-Control max-age for images, CSS and JavaScript
  • Blocking an abusive IP address or CIDR range without access to the main server config
  • Stopping other sites from embedding your images with hotlink protection
  • Allowing a separate front-end domain to call your API with CORS headers
  • Turning off directory listings on an uploads folder that has no index file

05Tips

  • If TLS ends at a load balancer or CDN, %{HTTPS} is always off on the origin, so the Force HTTPS rule loops. Test %{HTTP:X-Forwarded-Proto} !https instead.
  • Redirect matches by prefix, so Redirect 301 /blog /news also sends /blog/post to /news/post. Use RedirectMatch or a RewriteRule if you only want an exact path.
  • Test changes on a staging copy first. A syntax error in .htaccess returns 500 for the whole site, and you'll need file access to undo it.
  • After adding a 301, test with curl -I rather than a browser. Browsers cache permanent redirects, so a mistake can stick around even after you fix the file.

06Related concepts

mod_rewrite, Apache directives, 301 redirect, RewriteCond.

Frequently Asked Questions

What is .htaccess Generator?

.htaccess Generator is a free, browser-based developer tool on AIDToolStack. Generate Apache .htaccess rules for redirects, HTTPS, caching, and security. It requires no installation or sign-up and works entirely in your browser.

Is .htaccess Generator free to use?

Yes. No sign-up, no fees and no usage cap.

Does .htaccess Generator store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe