Skip to content

Free .htaccess Generator

Generate .htaccess rules for Apache. Force HTTPS, enable GZIP compression, set caching, prevent hotlinking. Free, with no sign-up required — everything happens right in your browser, so nothing you enter is sent to a server.

🔧 .htaccess Generator

How the .htaccess Generator Works

Tick the rules you want, such as Force HTTPS, GZIP compression, browser caching, Force WWW, custom error pages and hotlink protection, and the page builds the matching .htaccess code with comments. Copy it or download it as a file. Each option writes standard Apache directives, for example mod_rewrite rules for redirects, mod_deflate for compression and mod_expires for caching.

An .htaccess file works in Apache web servers when the server allows overrides, which many shared hosts do, and it has no effect on Nginx, IIS, Netlify or most static hosting platforms. A mistake in the file can take a site offline with a 500 error, so back up the existing file first, upload the new one to your site root and test straight away. Choose either the www or non-www version of your site, not both, or the redirects will loop.

Practical Use Cases

  • Redirect all visitors from HTTP to HTTPS after installing an SSL certificate.
  • Speed up a site by compressing text files and caching images, CSS and JavaScript.
  • Choose one canonical version of your site, with or without www.
  • Stop other websites from embedding your images and using your bandwidth.

Tips for Best Results

  • Back up your current .htaccess file before replacing it, so you can restore it quickly if your site returns an error.
  • Add the rules one at a time and test your site after each one. If something breaks, you know which rule caused it.
  • Choose either www or non-www and make sure your canonical tags, sitemap and links all use the same version.

Frequently Asked Questions

Apache web servers only. It does not work on Nginx or IIS, and most static hosting platforms ignore it. Check your hosting documentation.
Save it as .htaccess with the dot and no extension, upload it to your site's root folder, which is the folder that holds index.html, and test your pages.
A rule is not supported by your server. Remove the file or restore your backup, then add the rules one at a time to find the one that causes the problem.
Yes. Add the new rules to the existing file instead of replacing it, and make sure RewriteEngine On appears only once at the top of the rewrite section.
No. The file is generated in your browser and not sent anywhere.