DevToolPal
EN

.htaccess Generator

Generate an Apache .htaccess file: force HTTPS, www redirects, 301 redirects, 404 page, gzip, caching and security headers.

Runs locally, never uploaded

Options

.htaccess

0 chars · 0 B

What this tool does

The .htaccess Generator writes an Apache configuration file for the most common jobs: forcing HTTPS, choosing between www.example.com and example.com, permanent 301 redirects, a custom 404 page, gzip compression, browser caching, security headers, CORS, image hotlink protection and a fallback for single-page apps.

Each feature is a switch. The file updates as you change options, comes with short comments explaining every block, and wraps module-specific rules in <IfModule> so the site keeps working when a module is missing.

How to use it

  1. Enter your Domain (needed for the www and hotlink rules).
  2. Turn on the features you want. Force HTTPS and www prefix are combined into a single redirect, so visitors never bounce twice.
  3. Add 301 redirects as old new pairs separated by ;, for example /old-page /new-page; /blog https://blog.example.com.
  4. Copy the result or press Download to save it as .htaccess.
  5. Upload it to the document root of your site and test a few URLs, ideally on a staging server first.

Example

Forcing HTTPS and removing www for example.com produces:

<IfModule mod_rewrite.c>
RewriteEngine On

# Force HTTPS and remove www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]
</IfModule>

Tips

  • 301 redirects are cached by browsers. While testing, use a private window or clear the cache.
  • Turn on HSTS (part of the security headers when HTTPS is forced) only after HTTPS works on every subdomain.
  • Use the single-page app fallback for React, Vue or Angular apps that use client-side routing.

FAQ

› Where do I put the .htaccess file?

In the document root of your site (the folder that holds index.html or index.php) on an Apache server. Rules also apply to every folder below it.

› Will this work on Nginx?

No. .htaccess is read only by Apache and compatible servers such as LiteSpeed. Nginx needs the same rules written in its own server configuration.

› Why do I get a 500 error after uploading it?

Usually a module the file uses is not enabled. Each block is wrapped in <IfModule>, but mod_rewrite rules and Options -Indexes can still fail when the host disallows them via AllowOverride. Remove sections one by one to find the culprit.

› How do I write redirects?

Enter pairs of old path and new URL separated by semicolons, for example /old /new; /blog https://blog.example.com. Each pair becomes a permanent 301 redirect.