← All text tools

.htaccess Generator

Build an Apache .htaccess file with HTTPS and www redirects, gzip, caching, error pages, security headers, hotlink protection and IP blocking.

  • Free
  • No sign-up
  • Works on any device

About .htaccess Generator

Assemble an Apache .htaccess file from options, with a comment above each block. It can redirect HTTP to HTTPS (also behind a proxy or CDN that sends X-Forwarded-Proto), force www or remove it with a single redirect, turn off directory listings, hide dotfiles except /.well-known/, compress text with mod_deflate, set long browser cache times with mod_expires, send security headers, set custom 404 and 500 pages, block hotlinking of images, block IP addresses with Apache 2.4 syntax and add permanent redirects. Each module's rules sit inside IfModule so that a missing module does not stop the site.

How to use .htaccess Generator

  1. Enter your domain and tick the features you want, such as HTTPS, compression and caching.
  2. Add custom error pages, redirect lines such as /old-page /new-page, or IP addresses to block.
  3. Copy the result into a file named .htaccess in your web root and test the site, keeping a backup of any existing file.

Why use this tool?

Also known as

Frequently asked questions

Why does the redirect to HTTPS loop behind a CDN?

The server sees plain HTTP from the CDN even when the visitor used HTTPS. Choose the proxy setting so the rule reads X-Forwarded-Proto instead of the HTTPS variable.

Is HSTS safe to switch on?

Only when every page and subdomain works over HTTPS, because browsers will refuse plain HTTP for the full max-age, which is one year here. Test first with a short period elsewhere.

Will this work on nginx?

No. Nginx does not read .htaccess files, so the rules must be rewritten as server configuration. It is meant for Apache and compatible servers such as LiteSpeed.

Is .htaccess Generator free?

Yes. .htaccess Generator on Toolipedia is free to use, with no sign-up and no watermark.

Is it safe to use?

Yes. Everything is worked out in your browser, and nothing you enter is sent to our server.

Does it work on my phone?

Yes. It works in any modern browser on Android and iPhone, as well as on tablets and computers. There's nothing to install.

Do I need an account?

No. Just open the page and use the tool. There's no sign-up and no email needed.

Can I put .htaccess Generator on my own website?

Yes. Use the Embed on your site button under the tool to copy a short piece of code and paste it into your page. It is free, needs no account, and the tool keeps working inside your page.

Related tools