⚙️ .htaccess Generator

Generated .htaccess

Choose from common settings — forcing HTTPS, redirecting to a www subdomain, gzip compression, browser caching, disabling directory listings, and a custom 404 page — with simple checkboxes to generate a ready-to-use .htaccess file for Apache servers.

How to use

  1. Check the settings you need (force HTTPS, www redirect, gzip compression, browser caching, disable directory listing).
  2. Enter a path if you want a custom 404 page.
  3. Copy the generated content and paste it into your server's .htaccess file.

How the calculation works

.htaccess is the per-directory configuration file for the Apache web server. Pick common settings and this tool writes them out. • Force HTTPS: when %{HTTPS} is off, redirect with a 301 (permanent) to the https:// version of the same URL • Force www: when the host name does not start with www., redirect to the www. version • Gzip: compress HTML, CSS, JavaScript, JSON and more with mod_deflate • Browser caching: with mod_expires, cache images for a year and CSS/JavaScript for a month • Disable directory listing: Options -Indexes hides file lists for folders without an index.html • 404 page: ErrorDocument 404 sets the page shown when something is not found The mod_deflate and mod_expires blocks are wrapped in <IfModule>, so servers without those modules do not error.

Worked example

With "force HTTPS" and "disable directory listing" RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] Options -Indexes Visiting http://example.com/page redirects to https://example.com/page.

Things to be aware of

  • A mistake in .htaccess can take the whole site down with "500 Internal Server Error". Back up the original before editing and check the site straight after.
  • Nginx, some LiteSpeed setups and many cloud hosts do not use .htaccess or use different syntax. Check your server.
  • Behind a CDN or load balancer, %{HTTPS} may always be off, causing a redirect loop. Then you need to check the X-Forwarded-Proto header instead.

FAQ

Where should I put the .htaccess file?

Place it in the directory you want the settings applied to (usually your website's root directory). It requires an Apache server with the relevant modules (mod_rewrite, mod_deflate, mod_expires, etc.) enabled.

Does this work on Nginx?

No, .htaccess is an Apache-specific feature. On Nginx, you'd write equivalent directives directly inside a server block instead.

I added the file but nothing seems to happen — why?

This usually means the required Apache modules (mod_rewrite, mod_deflate, mod_expires) aren't enabled on your server, or the AllowOverride directive doesn't permit .htaccess to take effect for that directory. Check with your hosting provider or server admin.