.htaccess Generator

Build an Apache .htaccess file from tick boxes: HTTPS and www redirects, 301 redirects, compression, caching, security headers, error pages, IP blocking and hotlink protection.

SEO & Web Runs in your browser · no upload

Reviewed 23 November 2026 · Free · No account needed

ExecutionYour browserInput never leaves your tab
File retentionNoneNothing is stored
AccountNot requiredNo sign-up, no paywall
PriceFreeNo trial, no usage cap on the tool itself

How to use

  1. Tick the options you want. The HTTPS redirect, compression, caching and security headers are on to start with.
  2. Choose whether the site should always use www, never use it or be left as it is, and how long browsers may keep static files.
  3. Add redirects, one per line as the old path, a space and the new path, then any error pages, IP addresses to block and a domain to allow for images.
  4. Press Copy or Download, put the file in your site root as .htaccess and test your site straight away.

Example

Input: HTTPS redirect, no www, /old-page to /new-page

Output: A rewrite to https, a rule that removes www and Redirect 301 /old-page /new-page

How it works

Each option you tick adds a ready-made block of Apache directives, and the blocks are joined into one file in a safe order. Rewrite rules come first, with www before HTTPS so a visitor reaches the final address in as few redirects as possible. Paths, IP addresses and domains are checked before the file is built.

No calculation. The HTTPS redirect uses RewriteCond %{HTTPS} off and RewriteCond %{HTTP:X-Forwarded-Proto} !https, then RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. Caching uses mod_expires with one ExpiresByType line per file type. IP blocks use Require not ip inside a RequireAll block.

Another example

With HTTPS, no www and one redirect, the file starts with RewriteEngine On, then a rule that strips www and goes straight to https, then the HTTPS rule, then Redirect 301 /old-page /new-page. A visitor on http://www.example.com/old-page is sent to https://example.com/old-page, and the redirect then sends them on to /new-page.

Limits and edge cases

  • These are Apache rules. They work on Apache and on servers such as LiteSpeed that read .htaccess files, but not on nginx or Cloudflare Pages.
  • Your host must allow .htaccess overrides, and some directives such as Options can cause a 500 error on hosts that do not. If your site breaks, remove the last block you added.
  • Redirect lines match by prefix, so /blog also sends /blog/page to the new address followed by the rest of the path.
  • The generator checks paths, IP addresses and the domain for obvious mistakes. It cannot test the file against your server, so always test after uploading.
  • The HTTPS test also looks at the X-Forwarded-Proto header, so a site behind a proxy or CDN that handles HTTPS is not sent into a redirect loop.
  • HSTS is allowed only when the HTTPS redirect is on, because it tells browsers to refuse plain HTTP for a year.
  • If nothing is ticked, the file contains a comment saying so instead of being empty.
  • Lines that start with # in the redirect box are ignored, so you can leave notes.
  • A hotlink domain is lower-cased, www is removed and the dots are escaped, so Example.com allows example.com and www.example.com.

Privacy

The file is built in this browser tab from what you type. Nothing is uploaded or stored, and nothing is sent to your server.

About this page

Written and reviewed by Toolnexo on 23 November 2026. The limits above describe the published tool, not an idealised version of it. If a result looks wrong or the page is unclear, email [email protected] with the tool URL and what you entered. Corrections are published here.

Further reading

Guides that use .htaccess Generator

All guides →

Related tools

FAQ

Questions about .htaccess Generator

What is an .htaccess file?

It is a plain-text settings file that Apache web servers read for the folder it sits in and the folders below. It can redirect addresses, set error pages, compress files, control caching and block visitors without changing the main server settings.

Where do I put the .htaccess file?

In the root folder of your site, usually called public_html or htdocs. The name starts with a dot and has no extension. Some file managers hide files that start with a dot, so turn on the option to show hidden files. If your browser saves the download as htaccess without the dot, rename it to .htaccess.

Will it work on nginx?

No. nginx does not read .htaccess files and uses its own configuration syntax. These rules suit Apache and Apache-compatible servers such as LiteSpeed.

Why did my site show a 500 error after I uploaded it?

Usually the host does not allow one of the directives, or a module such as mod_headers or mod_expires is missing. Remove the last block you added, or the whole file, and add blocks back one at a time. The blocks for headers, caching and compression are wrapped in IfModule checks to reduce this.

Should I use a 301 or a 302 redirect?

Use 301 when an address has moved for good, so search engines pass its ranking to the new address. Use 302 for a temporary move that you plan to undo.

Does it work with WordPress?

Yes, but WordPress keeps its own block between the lines # BEGIN WordPress and # END WordPress. Put these rules above that block and do not edit inside it.