DevTools Logo

.htaccess Generator

.htaccess Generator

Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth.

Options

Rewrite rules

Error pages

Security headers (key: value, one per line)

.htaccess

# Generated by DevTools
Options -Indexes

# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^/old/(.*)$ /new/$1 [R=301,L]

# Custom error pages
ErrorDocument 404 /404.html

# Security headers
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
client-side
Apache

Examples

Force HTTPS

Input
HTTPS redirect on
Output
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

A 301 redirect sends every HTTP request to the same URL over HTTPS.

About this tool

The .htaccess Generator writes an Apache .htaccess from a set of options: forced HTTPS, rewrite rules, custom error pages, security headers, basic auth, and disabled directory indexes. Each section is emitted in order with correct directive syntax — nothing is uploaded.

How to use

  1. Toggle options

    Switch on HTTPS redirect, no-indexes, or basic auth as needed.

  2. Add rules and pages

    Add rewrite rules with flags and error documents for the codes you care about.

  3. Drop into the site

    Save the file as .htaccess in your document root.

Use cases

Pretty URLs

Rewrite friendly paths to internal handlers.

Lock down an admin area

Protect a directory with basic auth.

Common mistakes

Mistake:Using .htaccess on Nginx.

Fix:It is Apache-only; Nginx ignores .htaccess and needs its own rewrite rules.

Frequently asked questions

References & standards