.htaccess generator

Tick what you need and copy the finished .htaccess for Apache 2.4. Each rule uses standard directives, and your lists are checked line by line before they go into the file.

Host name
One per line: /old-path /new-path or a full URL, with an optional code (301, 302, 303, 307, 308). Default 301.
One per line: code and path, for example 404 /404.html.
One IPv4 or IPv6 address, or a range like 198.51.100.0/24, per line.

Save the text as .htaccess in your site root. Needs Apache with AllowOverride enabled; other servers such as nginx ignore this file.

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Switch on the features you need. The file updates as you type.
  2. Fix any line that the tool lists as invalid; those lines are left out of the output.
  3. Copy the result into a file named .htaccess in your site root, or append it to the existing one.
  4. Open your site and test every redirect with a private window, because browsers cache 301 redirects.

What each block writes

  • HTTPS and www: RewriteEngine On with RewriteCond and RewriteRule ... [L,R=301]. When you combine HTTPS with www, a single redirect goes straight to the final address instead of two hops.
  • Redirects: one Redirect <code> <from> <to> line each (mod_alias).
  • Error pages: ErrorDocument <code> <path>.
  • Directory listings: Options -Indexes.
  • IP blocking: Require all granted and Require not ip ... inside <RequireAll>, the Apache 2.4 syntax.
  • Compression: AddOutputFilterByType DEFLATE ... for HTML, CSS, JavaScript, JSON, XML and SVG, inside <IfModule mod_deflate.c>.
  • Caching: ExpiresByType <type> "access plus <time>" inside <IfModule mod_expires.c>.
  • Hotlink protection: a referrer check that returns 403 for image requests from other sites, while still allowing requests with an empty referrer.

Example

Choosing HTTPS and removing www writes a rule that sends http://www.example.com/page to https://example.com/page in one step, with the path and query string kept.

Tips

Start with a short cache time for CSS and JS unless file names change with each release, because a long cache hides updates from returning visitors. Back up the current .htaccess before replacing it.

Frequently asked questions

Where do I put the .htaccess file?

In the folder you want the rules to apply to, usually the web root next to index.html or index.php. Rules also apply to the sub-folders. The file name starts with a dot and has no extension.

Why do I get a 500 error after uploading it?

Usually a module is missing or the server does not allow overrides. The HTTPS, www and hotlink rules need mod_rewrite, and the .htaccess may only use the directives that AllowOverride permits. Remove blocks one by one to find the one that fails.

Will the HTTPS redirect work behind a CDN or proxy?

Maybe not. If TLS ends at a proxy, Apache sees plain HTTP on every request and the rule loops. In that case test the X-Forwarded-Proto header instead of %{HTTPS}, or let the proxy do the redirect.

Does a redirect match only that exact path?

No. The Redirect directive matches the beginning of the path and adds the rest to the target. Redirecting /blog to /news also sends /blog/post-1 to /news/post-1. List more specific paths first if they should go elsewhere.

Does this work on nginx?

No. nginx does not read .htaccess files; its redirects, caching and compression are set in the server configuration. LiteSpeed and OpenLiteSpeed do read most .htaccess rules.

More in Developer

All tools in this category: Developer ·Updated November 3, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.